sql quotes help

  • I want to get quotes after table1 and table2 using similar sql statement

    select +'sp_helpdb'''+name from sys.tables

    sp_helpdb 'table1

    sp_helpdb 'table2

    where should I put quotes to get

    sp_helpdb 'table1'

    sp_helpdb 'table2'

  • SELECT 'sp_helpdb ''' + name + '''' FROM sys.tables

    Please also note the added space after sp_helpdb.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • instead of quotes, you could use the builtin QUOTENAME function to get brackets, which would still be syntactically correct:

    SELECT 'EXEC sp_helpdb ' + QUOTENAME(name) + ' FROM sys.tables

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • A question regarding the logic rather than syntax: what do you want to do with it?

    sp_helpdb together with sys.tables doesn't seem to make much sense though...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • May be he intended for sp_help 'table_name', to get the entire table details, rather than sp_helpdb.

    Cheers

    John

  • Yes I wanted to do sp_help 'tablename'.

    Thanks for the replies.

  • How does four quotes make one quote while execution in this sql stmt after name?

    select +'sp_help '''+ name +'''' from sys.tables

  • Hi,

    In TSQL, the first and the last single quote marks the starting and ending of the string respectively. And every 2 single quotes, within the aforesaid quotes, represent one quote.

    John

  • thank you. that makes sense.

  • Lowell (1/1/2011)


    instead of quotes, you could use the builtin QUOTENAME function to get brackets, which would still be syntactically correct:

    SELECT 'EXEC sp_helpdb ' + QUOTENAME(name) + ' FROM sys.tables

    And, if you want single quotes you can use the second optional parameter for QUOTENAME to specify the character to be used. For example:

    SELECT 'EXEC sp_helpdb ' + QUOTENAME(name, char(39)) + ' FROM sys.tables;

    Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster
    Managing Transaction Logs

  • the quotename select stmt does not work

  • "does not work" is a rather vague statement. Can you post the code you're using and the related error message ?



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • It's just a typo.

    SELECT 'EXEC sp_help ' + QUOTENAME(name) FROM sys.tables

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]

Viewing 13 posts - 1 through 12 (of 12 total)

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