Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create Temp Table in Sql Server
Message
From
13/11/2014 01:52:40
Walter Meester
HoogkarspelNetherlands
 
 
To
12/11/2014 18:36:11
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01610894
Message ID:
01610903
Views:
65
>We're trying to create temporary tables in MsSql that can be used in later queries and have come up with something strange.
>TEXT TO lcSql TEXTMERGE NOSHOW PRETEXT 15
>  SELECT fieldlist
>    INTO #temp1
>    FROM table JOIN table ON condition
>         etc
>    WHERE datefield BETWEEN <<date1>> AND <<date2>>
>ENDTEXT
>
>?SQLEXEC(nHandle,lcSql)
>
>This returns 1.
>
>TEXT TO lcSql TEXTMERGE NOSHOW PRETEXT 15
>  SELECT fieldlist
>    INTO #temp2
>    FROM #temp1 JOIN table ON condition
>         etc
>    WHERE datefield BETWEEN <<date1>> AND <<date2>>
>ENDTEXT
>
>?SQLEXEC(nHandle,lcSql)
>
>This generates an error that #temp1 doesn't exist.
>
>It works if I change the query so that it creates ##Temp1
>
>I've only seen this happen when there are Date fields in the WHERE clause.
>
>I tried hard coding date values and got the same problem. I also tried using ? instead of the angle brackets without
>getting a better result.
>
>We're puzzled about why the extra # makes such a difference and any information you can provide
>will be a big help.
>
>Thanks.............Rich

Most likely this is caused because the first query runs in the SP_EXECUTESQL stored procedure. The temp table then is created in the scope of the stored procedure and automatically released when it finishes. Most common cause for it to have parameters in the query. Just check the SQL profiler how the query is exactly executed in SQL server.
Previous
Reply
Map
View

Click here to load this message in the networking platform