
August 29th, 2003, 02:36 PM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Problem with sp_executesql
My query runs clean however, it does absolutely nothing when using sp_executesql. When I run it without using sp_executesql it works fine, but I need sp_executesql to pass in different db names. When I run the query, no rows are updated and when I print my @SQLString variable it doesn't return anything at all. In looking through the server trace in QA everything is being set and executed like it should be... Any ideas? (Sorry for the voluminous code)
DECLARE @Id int, @Name varchar(100)
Set @id = 5
Set @Name = 'Shire'
Declare @SQLString nvarchar (4000)
DECLARE @IDAsChar nvarchar(100)
SET @SQLString = N'create table #objects (objectID int, dbID smallint)
insert into #objects (ObjectID, dbID)
select distinct o.id, ucv.dbID
from [[[Benditt.][' + @Name + '].][dbo].]sysobjects o join [[[Benditt.][' + @Name + '].][dbo].]syscomments c (nolock) on o.id = c.id
left outer join UWCustom.dbo.UW_Code_Versions ucv (nolock)
on o.id = ucv.objectId
and o.xtype = ucv.xtype
and u.name = ucv.OwnerName
and "' + @Name + '" = ucv.dbName
and o.name = ucv.ObjectName
and c.colid = ucv.colid
and ' + @IDAsChar + '= ucv.dbID
and LastVersion = "Y"
where o.xtype in ("P", "V")
and checksum(c.text) <> ucv.TextCheckSum
update UWCustom.dbo.uw_code_versions
set LastVersion = "N"
where ObjectID IN (select ObjectID from #Objects)
and dbID = ' + @IDAsChar + '
Insert into UWCustom.dbo.UW_Code_versions (
ObjectID
, xtype
, dbName
, dbID
, Ownername
, ObjectName
, colid
, DateEntered
, TextCheckSum
, text
)
select
o.id
, o.xtype
, ' + @Name + ' , ' + @IDAsChar + ' , u.name
, o.name
, c.colid
, getdate()
, checksum(c.text)
, c.text
from
#objects
join [[[Benditt.][' + @Name + '].][dbo].]sysobjects o (nolock) on #Objects.ObjectID = o.id
join [[[Benditt.][' + @Name + '].][dbo].]syscomments c (nolock) on o.id = c.id
join [[[Benditt.][' + @Name + '].][dbo].]sysusers u (nolock) on o.uid = u.uid
drop table #Objects'
PRINT @SQLString
EXEC sp_executesql @SQLString
GO
|