| Author |
Topic |
|
juicyapple
Posting Yak Master
176 Posts |
Posted - 2008-03-12 : 05:17:43
|
Hi, how to call the shrink_file proc from shrink_file_caller proc as below??CREATE PROCEDURE [dbo].[Shrink_File] @DBName VARCHAR(100),@err INT OUTPUTAS...GOCREATE PROCEDURE [dbo].[Shrink_File_Caller] @DBName VARCHAR(100),@err INT OUTPUTASSET NOCOUNT ON; DECLARE @nsql NVARCHAR(4000);SET @nsql = '' + @DBName + '.dbo.Shrink_File ''' + @DBName + ''', @err OUTPUT' ;EXEC sp_executesql @nsql,N'@err INT OUTPUT', @err = @err OUTPUT;GOdeclare @err int;EXEC Shrink_File_CALLER 'DATABASE1', @errselect @err as err; I get the error:Server: Msg 170, Level 15, State 1, Line 1Line 1: Incorrect syntax near 'DATABASE1'.(1 row(s) affected) |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-12 : 05:21:42
|
My head spins...You call the Shrink_File_CALLER sp with a specified database name, right?In that sp, you call dbo.Shrink_File with CURRENT database name, not the one passed as parameter? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
juicyapple
Posting Yak Master
176 Posts |
Posted - 2008-03-12 : 05:27:52
|
quote: Originally posted by Peso My head spins...You call the Shrink_File_CALLER sp with a specified database name, right?In that sp, you call dbo.Shrink_File with CURRENT database name, not the one passed as parameter? E 12°55'05.25"N 56°04'39.16"
assume that @DBName = 'DATABASE1'So when I execute shrink_file_caller (in database1),EXEC Shrink_File_CALLER 'DATABASE1', @err it will call shrink_file and pass in the @DBName and pass out the @err codeI just want to get the @err value...sorry if it is confusing |
 |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2008-03-12 : 05:37:18
|
| Try placingSET @nsql = 'EXEC ' + @DBName + '.dbo.Shrink_File ''' + @DBName + ''', @err OUTPUT' ; |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-12 : 05:38:23
|
TrySET @nsql = QUOTENAME(@DBName) + '.dbo.Shrink_File ' + QUOTENAME(@DBName, ''''), @err OUTPUT' E 12°55'05.25"N 56°04'39.16" |
 |
|
|
juicyapple
Posting Yak Master
176 Posts |
Posted - 2008-03-12 : 06:19:14
|
quote: Originally posted by Peso TrySET @nsql = QUOTENAME(@DBName) + '.dbo.Shrink_File ' + QUOTENAME(@DBName, ''''), @err OUTPUT' E 12°55'05.25"N 56°04'39.16"
seems something wrong with the code...SET @nsql = QUOTENAME(@DBName) + '.dbo.Shrink_File ' + QUOTENAME(@DBName, ''''), @err OUTPUT' the single quote in red shouldn't be there right?? |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-12 : 06:22:25
|
There was a typo. He meant this:SET @nsql = 'EXEC ' + QUOTENAME(@DBName) + '.dbo.Shrink_File ' + QUOTENAME(@DBName, '''') + ', @err OUTPUT' Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-12 : 06:23:36
|
Thanks Harsh. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
juicyapple
Posting Yak Master
176 Posts |
Posted - 2008-03-13 : 20:43:04
|
| Thanks all. It is working now. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-03-14 : 06:22:18
|
| Also make sure you read this fullywww.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|