MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 29th, 2003, 02:36 PM
Liz24 Liz24 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 Liz24 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old September 23rd, 2003, 10:43 AM
k@y k@y is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 k@y User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ciao,
ho avuto il tuo stesso problema... e sono capitata sul tuo post.
io ho risolto usando le tabelle temporanee con i doppi cancelletti (##tmpTable)
spero ti possa essere di aiuto
k@y

Reply With Quote
  #3  
Old October 13th, 2003, 07:47 AM
alaistair alaistair is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 5 alaistair User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 37 sec
Reputation Power: 0
Hi,

Your problem is that you are declaring :

DECLARE @IDAsChar nvarchar(100)

but then not setting anything to it, it is defaulting to NULL which then means that when you try to join a 'NULL' to any other text :

and ' + @IDAsChar + '= ucv.dbID

You'll get a NULL returned when you try to print it.

Hope this helps,

Alaistair

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Problem with sp_executesql

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap