Nested If statement and SQL

Results 1 to 4 of 4

Thread: Nested If statement and SQL

  1. #1
    Join Date
    Dec 1969
    Posts
    613

    Default Nested If statement and SQL

    &#039I&#039m having trouble with this nested if. I want to be able to update any of the following three, asset_cost,description or asset_at_cal. thx for any help in advance. scott<BR><BR><BR>Set rs = Server.CreateObject("ADODB.Recordset") <BR><BR>sql = "UPDATE [Minor Property]"<BR>If (asset_cost = "")Then<BR> sql = sql & " SET asset_cost=NULL"<BR> If (description = "") Then<BR> sql = sql & " SET description=NULL"<BR><BR> Elseif (asset_at_cal ="") then<BR> sql = sql & " SET asset_at_cal=Null"<BR> End If<BR><BR>ElseIf (description &#060;&#062; "") Then<BR> sql = sql & " SET description=&#039"&description&"&#039"<BR><BR> <BR>Elseif (asset_at_cal &#060;&#062;"") then<BR> sql = sql & " SET asset_at_cal=&#039"&asset_at_cal&"&#039"<BR> <BR>End If<BR>sql = sql & " WHERE serial_num=&#039"&serial_num&"&#039 AND model_num= &#039"&model_num&"&#039"<BR>rs.Open sql, Connect

  2. #2
    Join Date
    Dec 1969
    Posts
    915

    Default RE: Nested If statement and SQL

    Why not use 3 separate If ... Then statements???<BR><BR>If (asset_cost = "")Then<BR>sql = sql & " SET asset_cost=NULL"<BR>Else<BR>sql = sql & " SET asset_cost=&#039"&asset_cost&"&#039 "<BR>End If<BR><BR>...<BR><BR><BR>HTH<BR><BR>Jerry<BR><BR>< BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    613

    Default RE: Nested If statement and SQL

    thx for the reply jerry but I tried that and I get the following.<BR><BR>Microsoft OLE DB Provider for ODBC Drivers error &#039 80040e14&#039 <BR><BR>[Microsoft][ODBC Microsoft Access 97 Driver] Syntax error (missing operator) in query expression &#039&#039 1000&#039 SET description=&#039WIDEBAND LEVEL S&#039&#039. <BR><BR>/c0900/minorproperty/MPverify.asp, line 52 <BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    915

    Default RE: Nested If statement and SQL

    I think you want to get rid of the SET in the second 2 If statements.<BR><BR><BR>HTH<BR><BR>Jerry<BR><BR>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •