Dynamic Query

  • Comments posted to this topic are about the item Dynamic Query

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

  • 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]

  • easy one to start the day 🙂

  • 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/

  • Nice and simple one.

  • Good basic question.

  • 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]

  • 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.

    Thanks & Best Regards,
    Hany Helmy
    SQL Server Database Consultant

  • 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

  • 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.

    Thanks & Best Regards,
    Hany Helmy
    SQL Server Database Consultant

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

  • Nice easy question for me. 🙂

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

  • 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/

  • 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 37 total)

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