Hi there,
Im writing a query in which I wan to calculate a colum based on the values
of other columns, so what I wanted to do was something like
IF colType=3 then colRecovery * .234 ELSE colReverb * 0.6
How can I do this ??
Cheers
Hi
There is no IF in SQL Server, you need CASE:
SELECT YourField =
CASE ColType
WHEN 3 THEN colRecovery * 0.234
ELSE colReverb * 0.6
END
J.
Jason Sweby
Software Development Manager,
Carval Computing Limited, Plymouth, UK www.carval.co.uk
Payroll - HR - T&A - Access Control
"New Bee" <p
@p.com> wrote in message
news:u4hthpsoHHA.4188@TK2MSFTNGP02.phx.gbl...
> Hi there,
> Im writing a query in which I wan to calculate a colum based on the values
> of other columns, so what I wanted to do was something like
> IF colType=3 then colRecovery * .234 ELSE colReverb * 0.6
> How can I do this ??
> Cheers
Try:
SELECT
CASE WHEN colType=3 THEN colRecovery * .234 ELSE colReverb * 0.6
END
from
MyTable
--
Tom
----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau
"New Bee" <p
@p.com> wrote in message
news:u4hthpsoHHA.4188@TK2MSFTNGP02.phx.gbl...
Hi there,
Im writing a query in which I wan to calculate a colum based on the values
of other columns, so what I wanted to do was something like
IF colType=3 then colRecovery * .234 ELSE colReverb * 0.6
How can I do this ??
Cheers
-----------------------------------------------Reply-----------------------------------------------
Use CASE or COALESCE
"New Bee" <p
@p.com> wrote in message
news:u4hthpsoHHA.4188@TK2MSFTNGP02.phx.gbl...
> Hi there,
> Im writing a query in which I wan to calculate a colum based on the values
> of other columns, so what I wanted to do was something like
> IF colType=3 then colRecovery * .234 ELSE colReverb * 0.6
> How can I do this ??
> Cheers
THANK YOU ALL
"New Bee" <p
@p.com> wrote in message
news:u4hthpsoHHA.4188@TK2MSFTNGP02.phx.gbl...
> Hi there,
> Im writing a query in which I wan to calculate a colum based on the values
> of other columns, so what I wanted to do was something like
> IF colType=3 then colRecovery * .234 ELSE colReverb * 0.6
> How can I do this ??
> Cheers