[thelist] SELECT @Variable FROM Table

Darren Darren at web-bitch.co.uk
Fri Jul 27 10:32:01 CDT 2001


On 27 July 2001 at 16:07:50, evolt <mwarden at mattwarden.com> wrote:

WM> On Jul 27, Darren had something to say about [thelist] SELECT @Variable...

WM> Seems like it's your table structure that's making things hard. How about:

<grin>

If I could change the table structure I would have.  I'm seriously
considering tracking down the guy who did the table and doing mean and
nasty things to him! ;>

For anyone who's interested a couple of ways have been proposed as a
solution to this.

One way is to create a temp table and perform an 'INSERT INTO SELECT
+ at VarName ...' in the exec which gives you a table with one value in it
(note that you can't do a SELECT INTO as the table is only available for
the duration of the exec).  You can then just grab the value into your
variable.

An alternative route is using the sp_executesql sproc.

After a bit of scrabbling through the BOL I went with the sp_executesql
as it allows a lot more flexibility and you can pass parameters in and
out so no messing around with the second table.

Cheers,

Darren.





More information about the thelist mailing list