Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Using sp_executesql

Author  Topic 

ninel
Posting Yak Master

141 Posts

Posted - 2006-08-22 : 14:04:58
I have the following table:


CREATE TABLE [COUNTS] (
[sDatabase] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Universe] [int] NULL ,
[VoiceMessages] [int] NULL ,
[AMMessages] [int] NULL ,
[Disconnects] [int] NULL
) ON [PRIMARY]
GO

INSERT [COUNTS] (sDatabase, universe, voicemessages, ammessages, disconnects)
VALUES ('voicenet_NGEV1', 57794,0,0,0)

INSERT [COUNTS] (sDatabase, universe, voicemessages, ammessages, disconnects)
VALUES ('voicenet_AT1037', 5117,5029,55,33)


I need to execute the following query:

SELECT @Universe = Universe
@VM = VoiceMessages,
@AM = AMMessages,
@DI = Disconnects
FROM COUNTS
WHERE sDatabase = @sDatabase


I need to execute this query dynamically because I populate @sDatabase from another table.
I know I can use sp_executesql, but I can't get it to work.

Does anyone know how to do this?

Thanks,
Ninel

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-22 : 14:17:32
There's nothing that you've shown that requires sp_executesql or dynamic SQL. Could you show us how @sDatabase is being populated.

Tara Kizer
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-22 : 14:18:36
[code]SELECT @Universe = Universe
@VM = VoiceMessages,
@AM = AMMessages,
@DI = Disconnects
FROM COUNTS
WHERE sDatabase = (select somecol from sometable where somepk = somevalue)[/code]
Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-08-22 : 14:27:43
Check whether this helps

http://www.nigelrivett.net/SQLTsql/sp_executeSQL.html

Srinika
Go to Top of Page
   

- Advertisement -