IIF clause in a TSQL INSERT statment

  • Hello comunity

    I have the following problem with my INSERT query :

    insert into lr (lrstamp,letra,no,nome,morada,local,codpost,evalor,valor,edata,vdata,sdata,u_carteira,

    u_pagchpd,u_nrchpd,contado,ollocal,status,localol,

    ncont,pais,intid)

    values

    ('ADM07123167763,873091186',1,3320,'MARIA DA ENCARNAÇÃO FERREIRA','LUGAR DO MONTE',

    '','4535 LOUROSA',62.79,12588,

    IIF('2008-01-14' = '2008-01-14','2008-01-13','2008-01-14'),

    '2008-01-14','2008-01-14',

    1,1,'3 cheque',10,

    'CX01 CX - Sede',3,'B','133301230',1,'1')

    Incorrect syntax near '='.

    I need to compare to dates in my IIF clause , this dates are fields in a Xbase cursor.

    Someone could me some help

    Many thanks

    Luis Santos

  • Instead of IIF, try:

    case when '2008-01-14' = '2008-01-14' then '2008-01-13' else '2008-01-14' end

  • IIF is not a legal construct in Transact-SQL. You need to use the CASE statement instead.

    CASE when condition THEN true_value else False_value END

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Many thanks for all your replies, they works ok

    Luis Santos

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply