Loading ...
Sorry, an error occurred while loading the content.

Select in string

Expand Messages
  • Surya Saputra
    Dear all, How select record from string ; Jakarta n Bandung a exist record and input City is unlimited. Something like this : Declare @Str Varchar(1000) Set
    Message 1 of 4 , May 4, 2007
    • 0 Attachment
      Dear all,

      How select record from string ; Jakarta n Bandung a exist record and
      input City is unlimited.



      Something like this :



      Declare @Str Varchar(1000)

      Set @Str = '''Jakarta'',''Bandung'''

      Select City From COM_SUPPLIER Where City In ('+ @Str +')



      This retun 0 record.



      Best Regards,

      Surya A. Saputra





      [Non-text portions of this message have been removed]
    • Michael Weiss
      One way to do this is to use dynamic sql. Make your entire sql statement a string and then execute it. DECLARE @sqlString varchar(4000) DECLARE @Str
      Message 2 of 4 , May 4, 2007
      • 0 Attachment
        One way to do this is to use dynamic sql. Make your entire sql statement
        a string and then execute it.



        DECLARE @sqlString varchar(4000)

        DECLARE @Str varchar(1000)

        Set @Str = '''Jakarta'',''Bandung'''
        SET @sqlString = 'Select City From COM_SUPPLIER Where City In ('+ @Str
        +')'



        Exec @sqlString





        ________________________________

        From: SQLQueriesNoCode@yahoogroups.com
        [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Surya Saputra
        Sent: Friday, May 04, 2007 3:52 AM
        To: SQLQueriesNoCode@yahoogroups.com; sqlserver-indo@yahoogroups.com
        Subject: [SQLQueriesNoCode] Select in string



        Dear all,

        How select record from string ; Jakarta n Bandung a exist record and
        input City is unlimited.

        Something like this :

        Declare @Str Varchar(1000)

        Set @Str = '''Jakarta'',''Bandung'''

        Select City From COM_SUPPLIER Where City In ('+ @Str +')

        This retun 0 record.

        Best Regards,

        Surya A. Saputra

        [Non-text portions of this message have been removed]





        [Non-text portions of this message have been removed]
      • Rahul Verma
        Create Table #temp ( lStr VarChar(10) ) Declare @lStr VarChar(100) Set @lStr = A, B, C, D Set @lStr = @lStr + , While PatIndex( %,% , @lStr) 0 Begin
        Message 3 of 4 , May 4, 2007
        • 0 Attachment
          Create Table #temp
          (
          lStr VarChar(10)
          )
          Declare @lStr VarChar(100)
          Set @lStr = 'A, B, C, D'
          Set @lStr = @lStr + ','
          While PatIndex('%,%', @lStr) > 0
          Begin
          Insert Into #temp(lStr) Values(lTrim(rTrim(SubString(@lStr,1, PatIndex('%,%', @lStr)- 1))))
          Set @lStr = SubString(@lStr, PatIndex('%,%', @lStr)+ 1, Len(@lStr))
          End
          Select City From COM_SUPPLIER Where City In (Select * From #temp)



          Regards
          Rahul Verma

          Michael Weiss <mweiss@...> wrote:
          One way to do this is to use dynamic sql. Make your entire sql statement
          a string and then execute it.

          DECLARE @sqlString varchar(4000)

          DECLARE @Str varchar(1000)

          Set @Str = '''Jakarta'',''Bandung'''
          SET @sqlString = 'Select City From COM_SUPPLIER Where City In ('+ @Str
          +')'

          Exec @sqlString

          ________________________________

          From: SQLQueriesNoCode@yahoogroups.com
          [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Surya Saputra
          Sent: Friday, May 04, 2007 3:52 AM
          To: SQLQueriesNoCode@yahoogroups.com; sqlserver-indo@yahoogroups.com
          Subject: [SQLQueriesNoCode] Select in string

          Dear all,

          How select record from string ; Jakarta n Bandung a exist record and
          input City is unlimited.

          Something like this :

          Declare @Str Varchar(1000)

          Set @Str = '''Jakarta'',''Bandung'''

          Select City From COM_SUPPLIER Where City In ('+ @Str +')

          This retun 0 record.

          Best Regards,

          Surya A. Saputra

          [Non-text portions of this message have been removed]

          [Non-text portions of this message have been removed]






          ---------------------------------
          Here’s a new way to find what you're looking for - Yahoo! Answers

          [Non-text portions of this message have been removed]
        • Surya Saputra
          Thanks all _____ From: Michael Weiss [mailto:mweiss@x5solutions.com] Sent: Saturday, May 05, 2007 2:57 AM To: SQLQueriesNoCode@yahoogroups.com Subject: RE:
          Message 4 of 4 , May 6, 2007
          • 0 Attachment
            Thanks all



            _____

            From: Michael Weiss [mailto:mweiss@...]
            Sent: Saturday, May 05, 2007 2:57 AM
            To: SQLQueriesNoCode@yahoogroups.com
            Subject: RE: [SQLQueriesNoCode] Select in string



            One way to do this is to use dynamic sql. Make your entire sql statement
            a string and then execute it.

            DECLARE @sqlString varchar(4000)

            DECLARE @Str varchar(1000)

            Set @Str = '''Jakarta'',''Bandung'''
            SET @sqlString = 'Select City From COM_SUPPLIER Where City In ('+ @Str
            +')'

            Exec @sqlString


            <http://geo.yahoo.com/serv?s=97359714/grpId=9438758/grpspId=1705115366/m
            sgId=2865/stime=1178308902/nc1=3848576/nc2=3848547/nc3=3848642>




            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.