December 30, 2009 at 11:10 am
Here is an idea of what I actually intend to do:
I intend to check if each of about 20 or so files exist. And if a file exists, call the executable to run a job for each. My initial plan was to use the select case statement.
Something like this:
SELECT
CASE filename
WHEN 'filename1' THEN exec master.dbo.xp_cmdshell "filename1.bat"
WHEN 'filename2' THEN exec master.dbo.xp_cmdshell "filename2.bat"
and so on
But it seems that I cannot use the EXEC command within the SELECT CASE statement.
December 30, 2009 at 11:47 am
Why not use SSIS for this? Why would you want to use those old batch files? And also from within SQL. That is just bad news waiting to happen. Use SSIS to read the contents of the directory, if the file exists, then do something.
Andrew SQLDBA
December 30, 2009 at 11:55 am
AndrewSQLDBA (12/30/2009)
That is just bad news waiting to happen.
Heh... that's funny... I was just going to say the same thing about using SSIS. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
December 30, 2009 at 11:59 am
I have never had any issues with SSIS. Maybe it is time for a new server.
Andrew SQLDBA
December 30, 2009 at 12:01 pm
just so you know what the issue is:
in TSQL, a CASE statement is used to decide which data to return; it can only return one of the SQL datatypes. you cannot use a case statement to control a logic flow.
an IF statement can be used to control logic flow, so it should look something like this:
IF @filename = 'filename1'
exec master.dbo.xp_cmdshell "filename1.bat"
IF @filename = 'filename2'
exec master.dbo.xp_cmdshell "filename2.bat"
Everyone else already gave you great advice on a better way to handle this, I just wanted to point out the syntax issue.
Lowell
December 30, 2009 at 12:16 pm
Great catch
I looked at that and did not even see the error.
I think that I will be going home now, it has been a very long week already
Andrew SQLDBA
December 30, 2009 at 12:42 pm
AndrewSQLDBA (12/30/2009)
I have never had any issues with SSIS. Maybe it is time for a new server.Andrew SQLDBA
Heh... unlike most, I've never had an issue with SSIS because the other way works just fine and don't need SSIS. Contrary to popular belief, the other way is not "bad news waiting to happen". For the record, I don't believe SSIS is either. Maybe it's time to revisit what works.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply