Hello,
I'm trying to make some of my setup scripts more readable and less prone to error. Here's the type of code I have now in my SQLCMD scripts, which I run from management studio:
!!bcp "select * from Database1..Table1 where CreateDate > '7/11/2010'" queryout C:\junk\Table1.tab -n -SServerName1 -UTestUser -PTestPassword
!!bcp "select * from Database1..Table2 where CreateDate > '7/11/2010'" queryout C:\junk\Table2.tab -n -SServerName1 -UTestUser -PTestPassword
Instad of needing to hardcode the date in each statement, I'd like to be able to do something like this:
declare @Date1 datetime
select @Date1 = '7/11/2010'
!!bcp "select * from Database1..Table1 where CreateDate > @Date1" queryout C:\junk\BCPData\Table1.tab -n -SServerName1 -UTestUser -PTestPassword
!!bcp "select * from Database1..Table2 where CreateDate > @Date1" queryout C:\junk\BCPData\Table2.tab -n -SServerName1 -UTestUser -PTestPassword
Notice that in the second set of code, the date is no longer hardcoded.
Is there a way to do this, or are there good alternatives?
thanks for any ideas! Sylvia