June 3, 2002 at 9:32 am
i have to port a sql statement from mysql to mssql which goes like :
select fieldname=1 from tablename
which returns 1 for fieldname if its true else 0, but doesn't affect the rowcount. the syntax is not compatible at all, so i've built a stored proc in mssql. unfortunatly the tablename has a dynamic postfix which is submitted as an additional parameter. i thought
@count=(exec("select count(fieldname) from tablename"+@postfix+" where fieldname= 1 and id ="+@id))
and then check if the count is >0 or not for every id, but somehow that won't work.
any help would would be appreciated
jan
June 5, 2002 at 10:00 am
Try this instead:
create table #tmp1 (result int)
insert into #tmp1 exec(@sqlstatement)
select @count = result from #tmp1
also an fyi... string or varchar values in mssql are encapsulated in single quotes, not double quotes.
Hope this helps,
DanW
June 7, 2002 at 2:27 am
thanks for your help danW, but in between i found another way to do it:
instead of
select a=1 from ...
now in t-sql
select a = case count(a) when >0 then 1 else 0 from ...
hope i wrote it right, i didn't find the statement now, but anyway it worked that way.
jan
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply