Re: IF statement in SQL?
- From: "bakedmike via SQLMonster.com" <u15016@uwe>
- Date: Fri, 11 Nov 2005 18:45:18 GMT
Acct_Type is a column.
Is it possible to do an IF statement this way or do you have to write a
WHERE clause?
Does IFs only work with variables in T-SQL?
Thanks for the response and the where clause.
Hugo Kornelis wrote:
>(snip)
>>What I want to say is
>>
>[quoted text clipped - 10 lines]
>>NOT IN (Limitors) AND (db1.dbo..ACCOUNTS.ACCT_ID IN
>>(db2.dbo.COMPANY.CID FROM db2.dbo.COMPANY))
>
>Hi bakedmike,
>
>But what is this "Acct_Type"? Is it a variable? In that case, it should
>be prefixed with @, and the rest of the code is just fine.
>
>Or is Acct_Type a column in the Accounts table, and should the decision
>to match against either the COMPANY or the EMPLOYEE table me made on a
>per-row basis? In that case, try:
>
>INSERT INTO db2.dbo.Accounts (List of fields in table)
>SELECT List of Fields in Table
>FROM db1.dbo.Accounts
>WHERE db1.dbo.Accounts.ACCT_ID NOT IN (Limitors)
> -- The line above is bad syntax and won't run.
> -- I hope you just made a mistake when copying.
>AND ( ( db1.dbo.AcctType = 'C'
> AND db1.dbo.ACCOUNTS.ACCT_ID IN
> (SELECT db2.dbo.COMPANY.CID
> FROM db2.dbo.COMPANY))
> OR ( db1.dbo.AcctType = 'E'
> AND db1.dbo.ACCOUNTS.ACCT_ID IN
> (SELECT db2.dbo.COMPANY.CID
> FROM db2.dbo.EMPLOYEE)))
>
>Best, Hugo
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-mseq/200511/1
.
- Follow-Ups:
- Re: IF statement in SQL?
- From: Hugo Kornelis
- Re: IF statement in SQL?
- References:
- IF statement in SQL?
- From: bakedmike via SQLMonster.com
- Re: IF statement in SQL?
- From: David Portas
- Re: IF statement in SQL?
- From: bakedmike via SQLMonster.com
- Re: IF statement in SQL?
- From: Hugo Kornelis
- IF statement in SQL?
- Prev by Date: Re: IF statement in SQL?
- Next by Date: Re: IF statement in SQL?
- Previous by thread: Re: IF statement in SQL?
- Next by thread: Re: IF statement in SQL?
- Index(es):
Relevant Pages
|