Groups | Blog | Home
all groups > sql server data mining > november 2003 >

sql server data mining : Mental block on a query



Peter Newman
11/28/2003 5:07:45 AM
I have a table containing 6 fields ( Varchars )

I have ceated a query

Select F1, F2, F3, F4, F5, F6, Count(f1) AS TOTALRETURNED
From Table 1
Where (F1 = ' Value' AND F2 = ' Value)
Group By F1, F2, F3, F4, F5, F6, TotalReturned

This should only ever return 1 record. The problem i am
getting is if no record is found i an not getting any
retirn and i need to get TOTALRETURNED = 0. The query is
part of a DTS task and is output to a Global Variable.
Due to the nature of the DTS I need either a 0 or 1
returned

any ideas??
Vishal Parkar
12/2/2003 2:53:31 AM
Peter,

I don't think that could be possible but you have an option with you if, you have a flexibility of
changing the DTS package and replace this query by calling a stored procedure.

Inside the stored procedure you can have a t-sql script as shown in following example.

create procedure test_ret @val nvarchar(10), @val1 nvarchar(10)
as
declare @x int
Select @x = Count(f1)
From Table1
Where (F1 = @val AND F2 = @val1 )
Group By F1, F2, F3, F4, F5, F6

if @@rowcount = 0
return 0
Else
return @x
go

--calling above stored procedure, @y varible will have value of the returned count from the query.

declare @y int
exec @y= test_ret 'value1', 'value2'
print @y

--
- Vishal


AddThis Social Bookmark Button