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)
 Select Statement with an Exec?

Author  Topic 

Hakuzen
Starting Member

24 Posts

Posted - 2009-09-04 : 12:08:04
Hello, I'm working on a stored procedure that feeds data into a local VB app. Something about it puzzles me though, there is a select statement that is run in "exec()"

ALTER PROCEDURE [dbo].[effburstwo] @wo int,@opsq float,@fromdate varchar(25),@thrudate varchar(25),@shift char(1),
@wc char(12) AS
declare @strsqlshift varchar(65)
declare @strwo varchar(8)
declare @stropsq varchar(15)

select @strwo=convert(varchar(8),@wo),
@stropsq=convert(varchar(15),@opsq)

select @strsqlshift=
case
when @shift<>'*' then "and a.wtapid='"+@shift+"'"
else ""
end

exec("
select a.wtan8,b.abalph,a.wthrw,
case
when a.wttyr='1' then 'RUN'
when a.wttyr='2' then 'SETUP'
when a.wttyr='3' then 'CANCEL'
when a.wttyr='4' then 'QTY'
else '*'
end trantype,wtapid,wtsoqs,wtsocn,wtyst,wtdgl
from ibmprod.dbo.f31122 a, ibmprod.dbo.f0101 b
where a.wtan8=b.aban8 and a.wtdoco="+@strwo+
" and a.wtdgl between '"+@fromdate+"' and '"+@thrudate+"' and wtopsq="+@stropsq+" "+@strsqlshift+
" and a.wtmcu='"+@wc+"' order by wtdgl ")


Can anyone tell me why this is being executed? And pehaps if i'm lucky, why it would cause an odbc runtime error '3146' within the VB app?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-04 : 12:18:52
It is dynamic SQL because of the dynamic WHERE clause (@strsqlshift).

odbc runtime error - sorry I don't know.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Hakuzen
Starting Member

24 Posts

Posted - 2009-09-04 : 12:33:26
Interesting.. Well if anybody sees something that might be causing the Runtime Error, please let me know.. It says its an ODBC eror however I've confirmed proper odbc settings and permissions.
Go to Top of Page
   

- Advertisement -