Qouted String

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Khan

    Qouted String

    Hi all,
    I have a string user_name and it is saved in table with single

    qoutes, i mean if you view the table there are single qoutes on both
    sides of user_name like 'amir', it is saved with single qoutes. The
    problem is how can i write sql query with = comparison, i'm
    using
    select * from sasuser.Followu p where user_name= ' 'amir ' ';.

    I need to use single qoutes for the query, coz variable is string but
    how can i use single qoutes which are with the name itself.


    Thanx.

  • Erland Sommarskog

    #2
    Re: Qouted String

    Khan (amir@programme r.net) writes:[color=blue]
    > I have a string user_name and it is saved in table with single
    > qoutes, i mean if you view the table there are single qoutes on both
    > sides of user_name like 'amir', it is saved with single qoutes. The
    > problem is how can i write sql query with = comparison, i'm
    > using
    > select * from sasuser.Followu p where user_name= ' 'amir ' ';.
    >
    > I need to use single qoutes for the query, coz variable is string but
    > how can i use single qoutes which are with the name itself.[/color]

    To include the string delimiter in a string literal you need to double
    it:

    SELECT * FROM sasuser.Followu p WHERE user_name = '''amit''';

    Note that when you work from client code, you should use parameterised
    SQL commands, which makes this a non-issue..


    --
    Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

    Books Online for SQL Server 2005 at

    Books Online for SQL Server 2000 at

    Comment

    • Khan

      #3
      Re: Qouted String

      thanx erland,, its fine now.

      Comment

      Working...