Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OpenRowSet() and parameterization
Message
 
To
15/06/2021 06:59:14
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01681195
Message ID:
01681217
Views:
57
This message has been marked as the solution to the initial question of the thread.
>>I don't understand why you "lost" temporary table.
>>I use tow ways:
>>1) dynamic SQL with EXECUTE
>>2) OLE-DB
>
>This page explains it all :
>
>https://www.sommarskog.se/dynamic_sql.html
>
>The section "Temp Tables and Dynamic SQL" is exactly the situation.
>
>Have you found a way to use such approach without having to create the temporary table before so it would be in the scope?
>
>OpenRowSet() has to be used because we have to import some Excel data.

Hmm,

1) global temporary table
CREATE OR ALTER PROCEDURE dbo._mishap_sp(@lcTMP NVARCHAR(128))
AS
 DECLARE @lcSQL NVARCHAR(4000)
 SELECT @lcSQL=REPLACE(N'SELECT * INTO ##%TMP% FROM [INFORMATION_SCHEMA].[TABLES]', '%TMP%', @lcTMP)
 EXEC sp_executesql @lcSQL
 --SELECT * FROM #temp
GO

EXEC dbo._mishap_sp 'mytmp'
select * from  ##mytmp
drop table ##mytmp
GO
2) cursor parameter
DECLARE @lorsData CURSOR, @lcSQL NVARCHAR(MAX)

    SET @lcSQL='SET @loCursor = CURSOR LOCAL READ_ONLY FOR 
      SELECT *
        FROM '+@lcTABLENAME+' AA INNER JOIN #OBJECTs  AB ON AA.DATABASEID=AB.DATABASEID AND AA.OBJECTID=AB.OBJECTID AND ....
        WHERE AA.EVENTCLASS=44
        ORDER BY AA.EVENTSEQUENCE
        ;
       OPEN @loCursor'
 END

 EXEC sp_executesql @lcSQL, N'@loCursor CURSOR OUTPUT', @lorsData OUTPUT

 WHILE 0 = 0 BEGIN
   FETCH NEXT FROM @lorsData INTO @liEVENTSEQUENCE, ...
   IF @@FETCH_STATUS <> 0 BREAK


END
 CLOSE @lorsData
 DEALLOCATE @lorsData
MartinaJ
"Navision is evil that needs to be erazed... to the ground"

Jabber: gorila@dione.zcu.cz
Jabber? Jabbim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform