Re: IF statement in SQL?
- From: "David Portas" <REMOVE_BEFORE_REPLYING_dportas@xxxxxxx>
- Date: Tue, 8 Nov 2005 21:34:58 -0000
"bakedmike via SQLMonster.com" <u15016@uwe> wrote in message
news:570f23fad2491@xxxxxx
> Can I write an if statement in T-SQL for MSSQL2K or do I have to do it in
> the
> WHERE clause?
>
> Would like to say:
>
> IF field1 = e
> insert into db2.accounts from db1.accounts where in db2.employee
> IF field2 = c
> insert into db2.accounts from db1.accounts where in db2.company
>
>
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-mseq/200511/1
Yes, there is an IF construct, but your pseudo code doesn't make much sense.
In what table does "field1" exist? How is SQL supposed to know the table if
you don't specify it? Which row or rows in that table is your IF statement
intended to refer to? Most likely you should be using a WHERE clause,
perhaps with an EXISTS subquery, but without a better spec that's just a
guess.
--
David Portas
SQL Server MVP
--
.
- Follow-Ups:
- Re: IF statement in SQL?
- From: bakedmike via SQLMonster.com
- Re: IF statement in SQL?
- References:
- IF statement in SQL?
- From: bakedmike via SQLMonster.com
- IF statement in SQL?
- Prev by Date: IF statement in SQL?
- Next by Date: Re: IF statement in SQL?
- Previous by thread: IF statement in SQL?
- Next by thread: Re: IF statement in SQL?
- Index(es):
Relevant Pages
|
|