ExamNotes.net  -  IT certification portal

ForumsCertResearchTop sitesNewslettersFree email
HomeRegister


Exams Notes
Practice exams
Exam games
Questions by email
Online training
Training videos
College degrees
Boot camps
Book store
Links directory
Tell a friend
For webmasters




General discussions > Public newsgroups > microsoft.public.sqlserver.server > Passing parameter to stored procedure with embedded single quote

Show a Printable Version
Email This Page to Someone!
Receive updates to this thread



Author Passing parameter to stored procedure with embedded single quote
MLP
Guest




Registered: Not Yet
Location:
Country:
State:
Certifications:
Working on:

Total Posts: N/A
Passing parameter to stored procedure with embedded single quote

I have this stored procedure:

CREATE PROCEDURE getLoc
@Location varchar(200) = NULL

AS
select * from tblCust where Location IN (@Location)

When I called the stored proc: "exec getLoc @Location='la'", it
works.

If I want to pass multiple location such as 'la', 'sd' and so on,
why would I pass the values since each location needs to be
embedded inside single quote to make the query look like this:

select * from tblCust where Location IN ('la','sd')

Report this post to a moderator

Old Post 12-20-02 07:23 PM
Reply w/Quote Edit/Delete Message IP: Logged
John Fichera
Guest




Registered: Not Yet
Location:
Country:
State:
Certifications:
Working on:

Total Posts: N/A
Re: Passing parameter to stored procedure with embedded single quote

Not sure if this is the best way, but I guess you could do something like
this...

declare @input varchar(255),@final varchar(255)
select @input = 'sysusers,sysobjects'
select @final=char(39)+replace(@input
,',',char(39)+','+char(39))+ch
ar(39)
exec('select name from sysobjects where name in ('+@final+')')


"MLP" <MLP@Hotmail.com> wrote in message
news:l0KM9.27917$3t6.992@nwrddc03.gnilink.net...
> I have this stored procedure:
>
> CREATE PROCEDURE getLoc
> @Location varchar(200) = NULL
>
> AS
> select * from tblCust where Location IN (@Location)
>
> When I called the stored proc: "exec getLoc @Location='la'", it
> works.
>
> If I want to pass multiple location such as 'la', 'sd' and so on,
> why would I pass the values since each location needs to be
> embedded inside single quote to make the query look like this:
>
> select * from tblCust where Location IN ('la','sd')
>



Report this post to a moderator

Old Post 12-20-02 09:23 PM
Reply w/Quote Edit/Delete Message IP: Logged
MLP
Guest




Registered: Not Yet
Location:
Country:
State:
Certifications:
Working on:

Total Posts: N/A
Re: Passing parameter to stored procedure with embedded single quote

It is a good idea, but when I created this stored proc:

CREATE PROCEDURE test
@input varchar(255)
AS
declare @final varchar(255)

select
@final=char(39)+replace(@input
,',',char(39)+','+char(39))+ch
ar(39)
select name from sysobjects where name in (@final)

GO

It won't work when I do "exec test @input='sysusers,sysobjects'.
Do you know why? Is there a way to execute a string inside a
stored proc like you did?

MLP

John Fichera wrote:
> Not sure if this is the best way, but I guess you could do something like
> this...
>
> declare @input varchar(255),@final varchar(255)
> select @input = 'sysusers,sysobjects'
> select @final=char(39)+replace(@input
,',',char(39)+','+char(39))+ch
ar(39)
> exec('select name from sysobjects where name in ('+@final+')')
>
>
> "MLP" <MLP@Hotmail.com> wrote in message
> news:l0KM9.27917$3t6.992@nwrddc03.gnilink.net...
>
>>I have this stored procedure:
>>
>>CREATE PROCEDURE getLoc
>> @Location varchar(200) = NULL
>>
>>AS
>> select * from tblCust where Location IN (@Location)
>>
>>When I called the stored proc: "exec getLoc @Location='la'", it
>>works.
>>
>>If I want to pass multiple location such as 'la', 'sd' and so on,
>>why would I pass the values since each location needs to be
>>embedded inside single quote to make the query look like this:
>>
>> select * from tblCust where Location IN ('la','sd')
>>

>
>
>


Report this post to a moderator

Old Post 12-21-02 12:23 AM
Reply w/Quote Edit/Delete Message IP: Logged
All times are GMT.
Post new thread   Post reply


Forum Jump:
Rate This Thread:
Forum Rules:
Who Can Read The Forum? Any registered user or guest.
Who Can Post New Topics? Any registered user.
Who Can Post Replies? Any registered user.
Changes: Messages can be edited by their author.
Posts: HTML code is OFF. Smilies are ON. vB code is ON. [IMG] code is OFF.
 

ExamNotes forum archive


Powered by: vBulletin 2.2.8
Copyright ©2000, Jelsoft Enterprises Limited.

  Free Braindumps | mcse braindumps