November 13, 2008 at 8:14 am
I am calling a stored procedure from another stored procedure with the code below.
Set @SQL = '[' + @DBName + "].dbo.sp_WB_Defragmentation_2005 " + convert(varchar(30), @objectid) + ' ,' + convert(varchar(4), @indexid) + ' ,' + convert(varchar(30), @partitionnum) + ' ,' + convert(varchar(20), @frag)
Exec (@SQL)
The @DBName parameter is needed because I set the DB_Name() function in the called procedure to set the database I want the process to run in (this is a reindex and update stats script that cursors through all databases on a server).
Anyway, one of our servers has the dreaded Sharepoint DB that is called
SharePoint_AdminContent_550fcb4f-3c30-4c02-8aac-ecd5c806f132 and it obviously has hyphens in it. Once the code above runs the @SQL command shows up like this...
[SharePoint_AdminContent_550fcb4f-3c30-4c02-8aac-ecd5c806f132].dbo.sp_WB_Defragmentation_2005 53575229 ,1 ,1 ,97.2281
It has brackets around the Database name which I want because of the hyphens. However, I am still getting the following error and I can't figure out why. Any ideas?
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '-'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '-'.
November 13, 2008 at 9:05 am
Check the variable size. Might be a truncation issue because the db name is so long.
November 13, 2008 at 8:40 pm
Do a "PRINT @Sql" before you execute it and check the printed value to locate the error.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply