Wednesday, March 28, 2012

if exists help

Hi There,
What is the problem here, I can not find out, it always execute sql instead
of printing 'no'
if exists (select * from dbo.sysobjects where id = object_id('dividend') )
if exists (select syscolumns.name
from sysobjects inner join
syscolumns on
sysobjects.id = syscolumns.id
where sysobjects.name = 'member' and syscolumns.name = 'adgdr1' )
begin
SELECT 'ADMINSYS_DN_AVC' as [SchemeName], MEMBER.[PLAN],
DIVIDEND.DIVIDREF, DIVIDEND.AMOUNT, DIVIDEND.TAX_RELIEF, DIVIDEND.SECURITYRF
,
DIVIDEND.TAX_REL_PD,
DIVIDEND.TAXTRAN
FROM MEMBER INNER JOIN
DIVIDEND ON MEMBER.[PLAN] = DIVIDEND.[PLAN]
WHERE (DIVIDEND.TAX_RELIEF <> 0) AND (DIVIDEND.TAXTRAN = 0) AND
(MEMBER.MigrationFlag = 'C') OR
(DIVIDEND.TAX_RELIEF <> 0) AND (DIVIDEND.TAXTRAN IS
NULL) AND (MEMBER.MigrationFlag = 'C')
end
else
print 'no'
if write something like this it works fine
if exists (select * from dbo.sysobjects where id = object_id('dividend') )
if exists (select syscolumns.name
from sysobjects inner join
syscolumns on
sysobjects.id = syscolumns.id
where sysobjects.name = 'member' and syscolumns.name = 'addkr1' )
print 'yes'
else
print 'no'
Thanks
GaneshGanesh wrote:
> Hi There,
> What is the problem here, I can not find out, it always execute sql
> instead of printing 'no'
>
> if exists (select * from dbo.sysobjects where id =
> object_id('dividend') )
> if exists (select syscolumns.name
> from sysobjects inner join
> syscolumns on
> sysobjects.id = syscolumns.id
> where sysobjects.name = 'member' and syscolumns.name = 'adgdr1' )
> begin
> SELECT 'ADMINSYS_DN_AVC' as [SchemeName], MEMBER.[PLAN],
> DIVIDEND.DIVIDREF, DIVIDEND.AMOUNT, DIVIDEND.TAX_RELIEF,
> DIVIDEND.SECURITYRF, DIVIDEND.TAX_REL_PD,
> DIVIDEND.TAXTRAN
> FROM MEMBER INNER JOIN
> DIVIDEND ON MEMBER.[PLAN] = DIVIDEND.[PLAN]
> WHERE (DIVIDEND.TAX_RELIEF <> 0) AND (DIVIDEND.TAXTRAN = 0) AND
> (MEMBER.MigrationFlag = 'C') OR
> (DIVIDEND.TAX_RELIEF <> 0) AND (DIVIDEND.TAXTRAN
> IS NULL) AND (MEMBER.MigrationFlag = 'C')
> end
> else
> print 'no'
>
> if write something like this it works fine
>
> if exists (select * from dbo.sysobjects where id =
> object_id('dividend') )
> if exists (select syscolumns.name
> from sysobjects inner join
> syscolumns on
> sysobjects.id = syscolumns.id
> where sysobjects.name = 'member' and syscolumns.name = 'addkr1' )
> print 'yes'
> else
> print 'no'
Can you explain what you want the script to do so we can validate the
code you posted?
David Gugick - SQL Server MVP
Quest Software|||I have to guess a bit here.
Change the beginning of your procedure to this:

> if exists (select * from dbo.sysobjects where id = object_id('dividend') )
AND exists (select syscolumns.name ...
"Ganesh" <gsganesh@.yahoo.com> wrote in message
news:99A82BDA-F5B5-40DC-8C18-434D6B9C2665@.microsoft.com...
> Hi There,
> What is the problem here, I can not find out, it always execute sql
> instead
> of printing 'no'
>
> if exists (select * from dbo.sysobjects where id = object_id('dividend') )
> if exists (select syscolumns.name
> from sysobjects inner join
> syscolumns on
> sysobjects.id = syscolumns.id
> where sysobjects.name = 'member' and syscolumns.name = 'adgdr1' )
> begin
> SELECT 'ADMINSYS_DN_AVC' as [SchemeName], MEMBER.[PLAN],
> DIVIDEND.DIVIDREF, DIVIDEND.AMOUNT, DIVIDEND.TAX_RELIEF,
> DIVIDEND.SECURITYRF,
> DIVIDEND.TAX_REL_PD,
> DIVIDEND.TAXTRAN
> FROM MEMBER INNER JOIN
> DIVIDEND ON MEMBER.[PLAN] = DIVIDEND.[PLAN]
> WHERE (DIVIDEND.TAX_RELIEF <> 0) AND (DIVIDEND.TAXTRAN = 0) AND
> (MEMBER.MigrationFlag = 'C') OR
> (DIVIDEND.TAX_RELIEF <> 0) AND (DIVIDEND.TAXTRAN IS
> NULL) AND (MEMBER.MigrationFlag = 'C')
> end
> else
> print 'no'
>
> if write something like this it works fine
>
> if exists (select * from dbo.sysobjects where id = object_id('dividend') )
> if exists (select syscolumns.name
> from sysobjects inner join
> syscolumns on
> sysobjects.id = syscolumns.id
> where sysobjects.name = 'member' and syscolumns.name = 'addkr1' )
> print 'yes'
> else
> print 'no'
>
> --
> Thanks
> Ganesh|||Basically,
I want to execute a select statement based on the table and field existence
for each database
/* Powered by General SQL Parser at www.sqlparser.com */
IF EXISTS (SELECT *
FROM DBO.SYSOBJECTS
WHERE ID = OBJECT_ID('dividend'))
AND EXISTS (SELECT SYSCOLUMNS.NAME
FROM SYSOBJECTS
INNER JOIN SYSCOLUMNS
ON SYSOBJECTS.ID = SYSCOLUMNS.ID
WHERE SYSOBJECTS.NAME = 'member'
AND SYSCOLUMNS.NAME = 'adgdr1')
BEGIN
SELECT 'ADMINSYS_DN_AVC' AS [SchemeName],
MEMBER.[PLAN],
DIVIDEND.DIVIDREF,
DIVIDEND.AMOUNT,
DIVIDEND.TAX_RELIEF,
DIVIDEND.SECURITYRF,
DIVIDEND.TAX_REL_PD,
DIVIDEND.TAXTRAN
FROM MEMBER
INNER JOIN DIVIDEND
ON MEMBER.[PLAN] = DIVIDEND.[PLAN]
WHERE (DIVIDEND.TAX_RELIEF <> 0)
AND (DIVIDEND.TAXTRAN = 0)
AND (MEMBER.MIGRATIONFLAG = 'C')
OR (DIVIDEND.TAX_RELIEF <> 0)
AND (DIVIDEND.TAXTRAN IS NULL )
AND (MEMBER.MIGRATIONFLAG = 'C')
END
ELSE
PRINT 'no'
Thanks
Ganesh
"Raymond D'Anjou" wrote:

> I have to guess a bit here.
> Change the beginning of your procedure to this:
>
> AND exists (select syscolumns.name ...
> "Ganesh" <gsganesh@.yahoo.com> wrote in message
> news:99A82BDA-F5B5-40DC-8C18-434D6B9C2665@.microsoft.com...
>
>

No comments:

Post a Comment