NNTP-Posting-Date: Mon, 18 Jun 2012 14:35:19 -0500 From: "Mojo" Newsgroups: comp.databases.ms-sqlserver,microsoft.public.sqlserver,microsoft.public.sqlserver.misc,microsoft.public.sqlserver.programming Subject: Newbie question: how to use vars in TSQL DDL Date: Mon, 18 Jun 2012 20:34:59 +0100 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 Message-ID: Lines: 30 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-T07nnYnbnbJXGfhnbCMmXA99YDHRaz35B5myJGd5xQ+F9UhGz/0WkJ4NYSRwUMN1yMzHGJLl700A5xz!3Twglz8fEnJjQPkMvf8b+Jn37fE0Q0D5xgKG/q3QMlI2R02KltVcUnodyxzK7I5OMiWgqKpOJSm3!pmxV8wGApi5vhFxvBu4rPZIP X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2021 Path: csiph.com!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail Xref: csiph.com comp.databases.ms-sqlserver:1130 Hi All Apols if this a noddy question, but I just can't fathom it!!! :0) 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, ... .... I've tried this, but it appears as though my GO statements stop it from working. I'm probably wrong, but this seems to suggest that I need to set the var about 1 or 2 rows above the actual INSERT, which defeats my purpose. Is there a way round this? Thanks