Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with variables inside my select statement...

Status
Not open for further replies.

NSMan

Technical User
Aug 26, 2004
72
US
I'm having trouble using a user defined variable to tell a select statement inside my proc what database it is supposed to be selecting from. Here is the code.

-----------------------------------------------------------
alter PROCEDURE moveimg

(@olddb char(12),
@newdb char(12))

as

select
b.imgid as imgid,
(select sum(datalength(img)) from @olddb.dbo.imgs a where a.imgid <= b.imgid) as total,
c.objidref

into imgsplit

from
imp00001.dbo.imgs b,
choctawkrs.dbo.imglinks c

where
b.imgid=c.imgidref
 
This won't work. Variables cannot be used instead of DB/table/column names, even USE @olddb is not allowed. Try dynamic SQL way.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top