USING A DYNAMIC VARIABLE

  • hey guys, just a quick question:

    declare @set varchar(2000)

    set @set = ' DECLARE @employee_id int

    SELECT @employee_id = employee_id

    FROM ##employee

    WHERE code = ''AA'''

    SELECT @employee_id '

    if you exec this, it gives me a number eg. 65656

    how do i now , use this 'output' and assign it to a variable?

  • How bout

    DECLARE @employee_id

    SET @employee_id = (SELECT employee_id FROM ##employee WHERE code = 'AA')

    SELECT * FROM table1 WHERE fieldx = @employee_id



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Use a SP with "output" ?

    drop table ##employee

    go

    select 'AA' as code,123 as employee_id into ##employee

    go

    drop procedure p1

    go

    create procedure p1 @Code varchar(10),@@employee_id int output as

     SELECT @@employee_id = employee_id

     FROM ##employee

     WHERE code = @Code

    go

    declare @@emp_id int

    exec p1 'AA', @@emp_id output

    select @@emp_id

    --G--

  • perhaps something like that?

     

    set @max-2 = 0

    set @sql = 'SELECT @max-2 = max(ordinal_position) FROM tempdb.information_schema.columns WITH (NOLOCK) where table_name = '''+@temp_table + '2'''

    EXEC sp_executesql @sql, '@max int OUTPUT', @max-2 OUTPUT

    if @max-2 is not null print 'max: '+str(@MAX) else print 'max: null'

    karl

    Best regards
    karl

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply