Results 1 to 6 of 6

Thread: Simple Select Statement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    65

    Simple Select Statement

    Hi guys can you please take a look at this

    Below is my sample script
    Code:
    DECLARE @sku nvarchar(100)
    SELECt @sku = sku from ac_orderItems  where orderID = 12 and orderItemTypeID = 0
    Print @sku
    Then when i print @sku it give me a result of SampleB
    but i want to produced an output of 'SampleB' enclosed in a single quote.

    Thanks

  2. #2
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Simple Select Statement

    Quote Originally Posted by hamtaro^-^ View Post
    Hi guys can you please take a look at this

    Below is my sample script
    Code:
    DECLARE @sku nvarchar(100)
    SELECt @sku = sku from ac_orderItems  where orderID = 12 and orderItemTypeID = 0
    Print Chr(39) || @sku || chr(39) 
    Then when i print @sku it give me a result of SampleB
    but i want to produced an output of 'SampleB' enclosed in a single quote.

    Thanks
    Will that work?

    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Simple Select Statement

    For SQL Server change || to +
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Simple Select Statement

    'chr' is not a recognized function name, use char instead.
    Code:
    Print char(39) + @sku + char(39)
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Simple Select Statement

    SQL Server has a string function called QuoteName. The syntax is

    QUOTENAME ( 'character_string' [ , 'quote_character' ] )

    'quote_character' can be a single quotation mark ('), a left or right bracket ([] - default), or a double quotation mark (").

    Code:
    DECLARE @sku nvarchar(100)
    SELECt @sku = QuoteName(sku,'''') from ac_orderItems  where orderID = 12 and orderItemTypeID = 0
    Print @sku

  6. #6
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Simple Select Statement

    Quote Originally Posted by GaryMazzone View Post
    For SQL Server change || to +
    Quote Originally Posted by dee-u View Post
    'chr' is not a recognized function name, use char instead.
    Code:
    Print char(39) + @sku + char(39)
    This is how Microsoft confuses PL/SQL developers.

    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width