MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #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


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway