﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / Development  / Creating temp table in Batch file / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 08:46:12 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Creating temp table in Batch file</title><link>http://www.sqlservercentral.com/Forums/Topic729582-145-1.aspx</link><description>Thanks  to all for your effortsi went with the slightly different approach .i made a sql file  and execute it Thanks to ALL</description><pubDate>Mon, 08 Jun 2009 21:29:06 GMT</pubDate><dc:creator>Bhuvnesh</dc:creator></item><item><title>RE: Creating temp table in Batch file</title><link>http://www.sqlservercentral.com/Forums/Topic729582-145-1.aspx</link><description>Looks like some sort of connectivity issue...a) Is SQL Browser enabled?b) Are remote connections enabled (in SQL 2005 this is done via Surface Area Configuration Manager)c) What happens when you excute the following at command promptSqlcmd –S t2DBA03\report –EDo you get a "1&gt;" on the command prompt?And I'd recommend you use the -d switch (as given in the example) to connect to the appropriate database that has the "tmp" table created in it</description><pubDate>Mon, 08 Jun 2009 13:28:02 GMT</pubDate><dc:creator>winash</dc:creator></item><item><title>RE: Creating temp table in Batch file</title><link>http://www.sqlservercentral.com/Forums/Topic729582-145-1.aspx</link><description>hi below is rthe script  , i m using for BATCH script ---------------------------------------------------------------ECHO OFFREM Author: Bhuvnesh KumarREM Date: June 5, 2009REM Usage: FolderCheck [share_map_drive] [FolderName] [share_unc] [share_user] [share_pwd]ECHO ONnet use %1IF errorlevel 2 IF NOT errorlevel 1 GOTO FolderCheckIF errorlevel 0 GOTO UnmapDrive:UnmapDrivenet use %1 /delete5:33 PM 6/5/2009:FolderCheck net use %1 %3 %5 /USER:%4[b]Sqlcmd –St2DBA03\report –E –Q  "insert into tmp exec xp_cmdshell 'dir  R:'"[/b]net use %1 /delete:End------------------------------------------------------------------------------------ the line in BOLD , contains sql  code which is giving error Error:---------------------------------------------------------------------C:\WINDOWS\system32&gt;Sqlcmd ûSt2DBA03\report ûE ûQ  "insert into tmp exec xp_cmdshell 'dir  R:'" Sqlcmd: 'ûSt2DBA03\report': Unknown Option. Enter '-?' for help.---------------------------------------------------------------------can somebody resolve it or give me alternative code for it </description><pubDate>Mon, 08 Jun 2009 01:35:26 GMT</pubDate><dc:creator>Bhuvnesh</dc:creator></item><item><title>RE: Creating temp table in Batch file</title><link>http://www.sqlservercentral.com/Forums/Topic729582-145-1.aspx</link><description>I'm not sure if a temp table is the correct way to go in this case. It will be removed immediately after your batch file disconnects from database.I would use a state-full table. Here a little sample how to call SQLCMD to create a table and insert "dir C:\"[code="plain"]sqlcmd -S .\Sql2k8 -E -Q "CREATE TABLE MyCmd (Line VARCHAR(512)) INSERT INTO MyCmd EXECUTE xp_cmdshell 'dir C:\'" -d Sandbox[/code]</description><pubDate>Fri, 05 Jun 2009 08:29:51 GMT</pubDate><dc:creator>Florian Reischl</dc:creator></item><item><title>RE: Creating temp table in Batch file</title><link>http://www.sqlservercentral.com/Forums/Topic729582-145-1.aspx</link><description>Sorry, but i couldnt get your problme clearly.Though, as per i understood, you have one batch file, say mybat.bat on c:\, which will give list of dirs. Now, you are going to execute this batch file from sql server and try to insert result into a temp table, as [quote]insert into tmp exec xp_cmdshell 'DIR c:\'[/quote]If so, then you need to be clear about the output structure of your .bat file, and accordingly create temp table before executing above sql statement. OR1) change you .bat file and create output with comma saprated values.2) store this result into .csv file3) Try to import data from this .csv file into new(temp) table.</description><pubDate>Fri, 05 Jun 2009 05:38:03 GMT</pubDate><dc:creator>Kruti Kansara</dc:creator></item><item><title>Creating temp table in Batch file</title><link>http://www.sqlservercentral.com/Forums/Topic729582-145-1.aspx</link><description>hi,Below is the code which  i m using in SQL script.This is basically a batch file With the help of this file , i need to add all directories name into one temp table SQL CODE : insert into tmp exec xp_cmdshell  'DIR c:\'Can i anybody told me that how can i create temp table and use above query.please add your code in below ("---------''INSERT CODE HERE"------)Thanks --------------------------------------------------------------------------------ECHO OFFREM Author: Bhuvnesh KumarREM Date: June 5, 2009REM Usage: FolderCheck [share_map_drive] [FolderName] [share_unc] [share_user] [share_pwd]ECHO ONnet use %1IF errorlevel 2 IF NOT errorlevel 1 GOTO FolderCheckIF errorlevel 0 GOTO UnmapDrive:UnmapDrivenet use %1 /delete:FolderChecknet use %1 %3 %5 /USER:%4-----------''INSERT CODE HERE"---------------------------net use %1 /delete:End</description><pubDate>Fri, 05 Jun 2009 05:21:44 GMT</pubDate><dc:creator>Bhuvnesh</dc:creator></item></channel></rss>