Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
just.net
Starting Member
24 Posts |
Posted - 2010-09-21 : 04:04:38
|
Hi, I want to do something like this:ALTER PROCEDURE [dbo].[GetTest] @DB varchar(max)ASBEGIN SET NOCOUNT ON; SELECT [id] ,[date_start] ,[date_end] ,[total_nights] ,[first_name] ,[last_name] ,[rate_code] ,[user_email] FROM [@DB].[dbo].[Report]ENDhow can i selcet from another DB by parmater ? |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-09-21 : 04:21:24
|
ALTER PROCEDURE [dbo].[GetTest]@DB varchar(max)ASBEGINSET NOCOUNT ON;Declare @sql varchar(max)Set @sql=' SELECT [id],[date_start],[date_end],[total_nights],[first_name],[last_name],[rate_code],[user_email]FROM ' +@DB +'.[dbo].[Report]'-- print @sqlExec (@sql)ENDSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-09-21 : 04:31:04
|
Senthil - Nagore.Maybe you should read the link you posted.Dynamic sql like this is unsafe. You are not validating the input at all.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-09-21 : 04:36:36
|
quote: Originally posted by Transact Charlie Senthil - Nagore.Maybe you should read the link you posted.Dynamic sql like this is unsafe. You are not validating the input at all.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Ya i aware what you mention! need to validate the input!here considering the input was valid! Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
|
|
just.net
Starting Member
24 Posts |
Posted - 2010-09-21 : 04:45:20
|
Thank you all. |
|
|
|
|
|
|
|