Dynamic Query

  • Samith C

    Mr or Mrs. 500

    Points: 519

    Comments posted to this topic are about the item Dynamic Query

    [font="Verdana"] There is no Wrong time to do a Right thing 🙂 [/font]

  • Ron McCullough

    SSC Guru

    Points: 63877

    oops

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Mr. Kapsicum

    SSCertifiable

    Points: 6128

    easy one to start the day 🙂

  • kapil_kk

    SSC-Insane

    Points: 21316

    While using SELECT it will give the output in a commented lines while using EXEC it gives the error :crazy:

    declare @var Varchar(1000)

    set @var = '-- /* select ''Samith'' name

    */'

    select @var

    --Output: '-- /* select 'Samith' name */'

    set @var = @var + ' select ''sas'''

    select @var

    --Output:' -- /* select 'Samith' name */ + select 'sas''

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Bangla

    Hall of Fame

    Points: 3137

    Nice and simple one.

  • Anipaul

    SSC-Insane

    Points: 24681

    Good basic question.

  • Samith C

    Mr or Mrs. 500

    Points: 519

    Change to Text mode [Ctrl+t]

    and check the result

    You can see the difference 🙂

    [font="Verdana"] There is no Wrong time to do a Right thing 🙂 [/font]

  • Hany Helmy

    SSChampion

    Points: 13488

    kapil_kk (9/23/2013)


    While using SELECT it will give the output in a commented lines while using EXEC it gives the error :crazy:

    declare @var Varchar(1000)

    set @var = '-- /* select ''Samith'' name

    */'

    select @var

    --Output: '-- /* select 'Samith' name */'

    set @var = @var + ' select ''sas'''

    select @var

    --Output:' -- /* select 'Samith' name */ + select 'sas''

    True.

  • Carlo Romagnano

    SSC-Insane

    Points: 21943

    kapil_kk (9/23/2013)


    While using SELECT it will give the output in a commented lines while using EXEC it gives the error :crazy:

    declare @var Varchar(1000)

    set @var = '-- /* select ''Samith'' name

    */'

    select @var

    --Output: '-- /* select 'Samith' name */'

    set @var = @var + ' select ''sas'''

    select @var

    --Output:' -- /* select 'Samith' name */ + select 'sas''

    Maybe, you have the resultset in grid mode! Change it to text mode and you'll see the "*/" at newline

  • Hany Helmy

    SSChampion

    Points: 13488

    Although I was pretty sure that this is another tricky question and my answer will be wrong when I pressed Submit button; but surprisingly it was correct 🙂

    exec @variable; hmmm always good to refresh the mind with hidden & forgotten basics.

  • Jamsheer

    Ten Centuries

    Points: 1136

    I LOVE TRICKY QUESTIONS ALWAYS... THANKS SAMITH..

  • sqlnaive

    SSCoach

    Points: 17435

    Nice easy question for me. 🙂

  • ksatpute123

    Hall of Fame

    Points: 3325

    I had to think about it for a while before answering. Good one.

  • psingla

    Hall of Fame

    Points: 3840

    ksatpute123 (9/24/2013)


    I had to think about it for a while before answering. Good one.

    same here.Thanks Smith

    Pramod
    SQL Server DBA | MCSE SQL Server 2012/2014

    in.linkedin.com/in/pramodsingla/
    http://pramodsingla.wordpress.com/

  • Koen Verbeeck

    SSC Guru

    Points: 258965

    Very nice question, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 15 posts - 1 through 15 (of 38 total)

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