Re: IF statement in SQL?



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
.



Relevant Pages

  • Re: Query
    ... "Hugo Kornelis" wrote: ... passing a where clause to a stored procedure is a token of a weak ... Remember that SQL Server will call them for each row in the ... > * Check the execution plan. ...
    (microsoft.public.sqlserver.programming)
  • Re: IF statement in SQL?
    ... Okay, here's the two statements I wanted to run using an if instead of ... seperate statements. ... NOT IN (Limitors) AND (db1.dbo.ACCOUNTS.ACCT_ID IN ... Most likely you should be using a WHERE clause, ...
    (microsoft.public.sqlserver.mseq)
  • Re: Straw poll - naming conventions
    ... > mine ifs are: ... > I hate Borland's way to write else clause. ... All my "begins" start on a new line for universal consistency. ...
    (borland.public.delphi.non-technical)
  • Re: Straw poll - naming conventions
    ... mine ifs are: ... I hate Borland's way to write else clause. ... Andrew Rybenkov. ...
    (borland.public.delphi.non-technical)