sql server stored procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ganesh22
    Banned
    New Member
    • Sep 2007
    • 81

    sql server stored procedure

    Hi,
    i writen stored procedure for getting values based on location but my problem is if i entered single location means its working but if i enteres multi location means its not working
    ex: if i entered Chennai means its working then if i entered Chennai,Bangalo re means its not working???

    set ANSI_NULLS ON
    set QUOTED_IDENTIFI ER ON
    GO
    ALTER PROCEDURE [dbo].[Get]
    @ID varchar(500)=NU LL,
    @Location varchar(50)=NUL L
    AS
    BEGIN
    select * from Details where Location in (@Location)
    End
  • deepuv04
    Recognized Expert New Member
    • Nov 2007
    • 227

    #2
    Originally posted by ganesh22
    Hi,
    i writen stored procedure for getting values based on location but my problem is if i entered single location means its working but if i enteres multi location means its not working
    ex: if i entered Chennai means its working then if i entered Chennai,Bangalo re means its not working???

    set ANSI_NULLS ON
    set QUOTED_IDENTIFI ER ON
    GO
    ALTER PROCEDURE [dbo].[Get]
    @ID varchar(500)=NU LL,
    @Location varchar(50)=NUL L
    AS
    BEGIN
    select * from Details where Location in (@Location)
    End
    Hi
    Try the following code...
    Here pass the @Location value like Banglore,Chenna i,....

    [code = sql]
    set ANSI_NULLS ON
    set QUOTED_IDENTIFI ER ON
    GO
    ALTER PROCEDURE [dbo].[Get]
    @ID varchar(500)=NU LL,
    @Location varchar(50)=NUL L
    AS
    BEGIN
    select * from Details
    where (','+isnull(@Lo cation,convert( varchar(100),Lo cation) )+',') like
    ('%,'+convert(v archar(20),Loca tion)+ ',%')

    End

    [/code]

    Thanks

    Comment

    • ganesh22
      Banned
      New Member
      • Sep 2007
      • 81

      #3
      Hi, Deepu!
      Thanx for reply!, Its Working

      Comment

      Working...