August 12, 2009 at 3:11 pm
Hi all,
hope this is a quick and dirty one but how do I state a declare variable to be equal to a field within a table ?
Something like this:
Set @ months = (I want to pull ADateFiled from TableA)
Thanks in advance,
Mitch
August 12, 2009 at 3:34 pm
Like this:
Set @ months = (SELECT ADateFiled from TableA WHERE ...)
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
August 12, 2009 at 3:46 pm
Thank you Sir, much appreciated !!
August 12, 2009 at 3:51 pm
Glad I could help.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
August 17, 2009 at 5:53 am
Another good option to be aware of is that you can assign values directly from your SELECT statement...
SELECT @valueA = Field1 FROM someTable WHERE...
This offers the ability to assign multiple values from the same record in one statement. For example, you can use:
SELECT @valueA = Field1, @valueB = Field2 FROM someTable WHERE...
Instead of:
SET @valueA = (SELECT Field1 FROM someTable WHERE...)
SET @valueB = (SELECT Field2 FROM someTable WHERE...)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply