Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 18,675 of 19,505    |
|    Erland Sommarskog to Mojo    |
|    Re: Newbie question: how to use vars in     |
|    18 Jun 12 23:42:53    |
      XPost: microsoft.public.sqlserver, microsoft.public.sqlserver.misc,       microsoft.public.sqlserver.programming       From: esquel@sommarskog.se              Mojo (please@dont.spam.com) writes:       > I use a long SQL script (DDL ??) to drop, create and populate my db each       > time (rather than a backup) and initially the DB needs key values inserted       > into it.       >       > At the mo, I try to remember to scroll up and down the script (quite       > long now) to populate it with the required values for the given time,       > but I much rather do what I used to do in MySQL, which was to put       > varaibles at the very top of my script so that the values entered at the       > top then reflect further down, eg       >       > Line 1 : SET @MyYear= 2012;       > ....       > ....       > ....       > Line 304: .INSERT ... .... ....., @MyYear, ... ....              As long as you are only setting parameters to the script, you can use       SQLCMD. I am not here going to show an example, because I don't use       SQLCMD variables myself. Rather read the topic on SQLCMD in Books       Online.              Keep in mind that these variables are set client-side, so there can be       no interaction what is going in SQL Server.              --       Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se              Links for SQL Server Books Online:       SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx       SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca