selecting query at run time

  • Hi everyone i am a newbie to ms sql i am using ms sql server 2000 i am selecting query at run time in sql editor so i have used the below code its giving exception that:No Resultset was produced any suggestions help me to solve this. Thanx this is my code.

    DECLARE @siteid VARCHAR, @spaceid VARCHAR

    Set @siteid = 'select distinct spaceid from staging.dbo.owner where siteid =' + quotename(@siteid, '''')

    set @spaceid = 'select country,state,city,fromdate,todate,url,cost from staging.dbo.myads' + quotename('myads' + @spaceid)

    exec(@siteid)

    exec(@spaceid)

  • can you try the below code

    DECLARE @siteid VARCHAR(500), @spaceid VARCHAR(600)

    Set @siteid = 'select distinct spaceid from staging.dbo.owner where siteid =' + quotename(ISNULL(@siteid,''), '''')

    set @spaceid = 'select country,state,city,fromdate,todate,url,cost from staging.dbo.myads' + quotename('myads' + ISNULL(@spaceid,''))

    exec(@siteid)

    exec(@spaceid)

  • Thanx for ur response it is generating spaceids of related siteid but i want to get this data at run time without declaration and also i want to display the whole fields i.e., country,state,city,fromdate,todate,url,cost fields also

    any suggestions please

  • Hi i am passing string at run time and getting the spaceid's for that user but below code is giving

    user as output pls verify this code and send me

    DECLARE @user VARCHAR(1000), @spaceid INT

    DECLARE @s-2 VARCHAR(1000), @r varchar(1000)

    set @user ='cat'

    set @spaceid =''

    Set @s-2 = 'select user from staging.dbo.site where user = ' + quotename(@spaceid,'''')

    set @r = 'select country,state,city,fromdate,todate,url,cost from staging.dbo.' + quotename('myads' + cast(@spaceid as varchar(11)))

    exec(@s)

    exec(@r)

    Thanx

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

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