TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Uwak Peter
1.6k
96
7k
How do i pass database name as parameter to stored procedure
Jun 3 2014 8:54 AM
Hello Everyone,
I am trying pass database name as parameter to a stored procedure, but iam having issues doing it, please check my script, and let me know if i am missing anything:
set quoted_identifier off
go
ALTER procedure [dbo].[usp_accessdb]
@SchoolAngelPortalDB varchar(128),
@GSC_NewSchoolCore varchar(128),
@schoolName varchar(50)= NULL
as
declare @query varchar(1000)
set @query = 'SELECT pp.title, pp.surname,pp.firstname,pp.phone,pp.email,rcd.reg_code,pp.genCode
FROM '+@SchoolAngelPortalDB+'.dbo.primaryparent pp
LEFT JOIN '+ @GSC_NewSchoolCore +'.dbo.registration_codes rcd ON pp.genCode = rcd.reg_code
WHERE Sch.Name='+@schoolName
exec (@query)
go
When trying to execute the procedure,using the below script:
[usp_accessdb]"SchoolAngelPortalDB","GSC_NewSchoolCore","Greenwood House School"
I have this error:
Incorrect syntax near 'House'.
Please any assistance will be appreciated.
Reply
Answers (
1
)
Does high vol. of #tmp tbls(hundred over) effect CPU Memory
How to get sql server table data into excel using webservice