문제

Does anybody face an issue when you drop a temporary table at the Sybase ASE 12 it still persists at a current session. So you encounter "Table already exists" when trying to select data into it again

도움이 되었습니까?

해결책

Well, you need to read the manuals, at least the syntax for the commands you expect to use, before you write code. Otherwise you will face issues at every turn. It depends on what you are trying to do.

  1. SELECT ... INTO #MyTable creates a table and succeeds because it does not exist. So a second SELECT ... INTO #MyTable will try to create #MyTable, find that it exists, and fail.

  2. If you want to perform a second SELECT into the same table, TRUNCATE the table, then use SELECT ... INTO EXISTING TABLE #MyTable.

  3. Or DROP TABLE and skip the EXISTING TABLE modifier.

  4. If you want the table to contain the sum of several SELECTS, obviously, skip the TRUNCATE.

다른 팁

I normally do this:

1) CREATE TABLE #temptable ( ....

)

INSERT INTO #temptable SELECT .....

This will never give error.

This solves another possible error . If the WHERE clause accompanying the "select INTO " yields no rows, the temporary table will not have zero rows but the temporary table won't be created at all. This could make the stored proc blow up later.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top