Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server Management Studio 2005

Status
Not open for further replies.

PWD

Technical User
Jul 12, 2002
823
GB
Good afternoon, I was just wondering if it were possible to uses an alias for a variable in code. For example I'd like to have StartDate = '01-July-2014' so I could put StartDate in my code and only have to change it in one place.

Probably a daft idea, but hey ho! [rednose]

Many thanks,
D€$
 
I'd consider it a good programming practice rather than a daft idea. Declare and set a variable at the top of your code, then use that variable in place of any constant values...

Code:
DECLARE @StartDate DATE = '2014-07-01'

-- Then use the variable anywhere in your code
SELECT *
  FROM YourTable
 WHERE StartDate = @StartDate

I hope I didn't misread you intent; the example isn't an alias for a variable but an actual variable. I don't believe there's such a thing as an alias for a variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top