Usage of SQL Temp Table query in VBScript

Pavan Kumar Midde 21 Reputation points
2021-10-01T10:20:15.75+00:00

Hi All,

I want to create a SQL Temp table and make use of it(Temp Table) in another SQL Query.
Below is the sample script that I have created.

Note: There are many columns in Temptable(#temptable) where i wnat to return only few. Therefore I havent mentioned all the column names here.

So help me to complete the script without any issues

Dim v1,v2,v3,v4,resp,fullres
SET shell = createObject("WScript.Shell")

SET v1= shell.Exec("sqlcmd -E -S server-name -d DBName -Q""Select * into #temptable from ABC where companyid = 100""")

SET v2 = shell.Exec("sqlcmd -E -S server-name -d DBName -Q""Select * from #temptable""")

SET v3 = v2.StdOut

fullres = v2.ReadAll

WScript.Echo""& fullres

0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 114.5K Reputation points
    2021-10-01T11:26:06.723+00:00

    Try another name: ##temptable.

    0 comments No comments