August 25, 2006 at 4:55 am
Hi,
I put a SELECT statement in execute sql task and it return no record. I want to handle this retireved value. i.e. if there are records retrieved, do a), if no, do b).
I know i can use the Count(*) and store the result to global variable. But i also need put the fields value to global variables too if there are records.
What's the best way to do that? or use other task?
thanks
August 28, 2006 at 8:00 am
This was removed by the editor as SPAM
August 28, 2006 at 8:26 am
You might try querying @@rowcount. It should contain the number of rows in your result set.
August 28, 2006 at 10:00 am
You could do
IF EXISTS (SELECT ...)
BEGIN ...
END
ELSE
August 28, 2006 at 12:30 pm
Here's what I do. This stored procedure query looks for errors in a table after users at various sites have entered data. If a site has no errors, they get a report that gives blanks where they would normally have data, and a message telling them they have done a good job.
SELECT
InsCo,
Patient,
PtNum,
CertLen,
CertNo,
CertScreen,
InsCd,
InsName,
Site
FROM
VtblCertNoValidAllIns
WHERE
Site = @Site
UNION
--if there are no results for a site
--give a default message
SELECT
'' InsCo,
'' Patient,
'' PtNum,
'' CertLen,
'' CertNo,
'All OK, Good Job!' CertScreen,
'' InsCd,
'' InsName,
@Site Site
WHERE NOT EXISTS
(SELECT
Site
FROM
VtblCertNoValidAllIns
WHERE
Site = @Site
)
August 28, 2006 at 2:33 pm
I use exists too.
see this part of a for next loop
if NOT exists (
select sysobjects.name, syscolumns.name from syscolumns, sysobjects
where sysobjects.id = object_id('TblRapporten')
and OBJECTPROPERTY(sysobjects.id, N'IsUserTable') = 1
and syscolumns.name= @KOLOMNAAM
and sysobjects.id = syscolumns.id
and (sysobjects.xtype='U' or sysobjects.xtype='S')
 
BEGIN --if
/* DE COLOM BESTAAT NIET, DUS MAAK HEM AAN */
EXEC('ALTER TABLE TblRapporten ADD ['+ @KOLOMNAAM + '] BIT NULL ' )
END --if
August 28, 2006 at 2:44 pm
Thanks you all for the reply.
But my question is to store the resaults (no record or has records with the fields values) to global varibles in Execute SQL task in DTS packages.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply