Consulting

Results 1 to 3 of 3

Thread: If argument in SQL query

  1. #1

    Question If argument in SQL query

    Hi All,
    I have the following query written in Excel (VBA), but isthere a way to insert an if/then /else statement into it?

    [vba]
    SQL = "SELECT #tmpFR10.MySelect, #tmpFR10.Tpnd,#tmpFR10.Descrip, #tmpBSQB.Act_BOH, #tmpBSQB.PALLET_QTY, #tmpBSQB.sTOCK_I,#tmpBSQB.Multi_p, "
    SQL = SQL & "#tmpBSQB.s_dock, #tmpBSQB.non_s_dock,#tmpFR10.CUBE, #tmpFR10.Weight, LEFT(whs.dw_prodbpr.SubGroup,4),LEFT(whs.dw_prodbpr.SubGroup,3) FROM #tmpFR10 " _
    & " LEFT JOIN whs.Focus_Prodtut ON #tmpFR10.tpnd =whs.Focus_Prodtut.Tpnd " _
    & " LEFT JOIN whs.dw_prodbpr ONwhs.Focus_Prodtut.Tpnb = whs.dw_prodbpr.Tpnb " _
    & " LEFT JOIN #tmpBSQB ON #tmpFR10.TPND =#tmpBSQB.TPND"


    [/vba]


    In addition to the above I wish to say

    If #tmpBSQB.Act_BOH > (#tmpBSQB.s_dock + #tmpBSQB.non_s_dock)) THEN #tmpBSQB.Act_BOH ELSE (#tmpBSQB.s_dock +#tmpBSQB.non_s_dock)
    The results being output to a new column. i’m ok with VBA but only just starting with SQL.
    Any help would be appreciated. Thanks,























    Last edited by jazznaura; 08-30-2011 at 11:28 AM. Reason: VBA Tags not working

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    SQL = "SELECT #tmpFR10.MySelect, " & _
    " #tmpFR10.Tpnd, " & _
    " #tmpFR10.Descrip, " & _
    " #tmpBSQB.Act_BOH, " & _
    " #tmpBSQB.PALLET_QTY, " & _
    " #tmpBSQB.sTOCK_I, " & _
    " #tmpBSQB.Multi_p, " & _
    " #tmpBSQB.s_dock, " & _
    " #tmpBSQB.non_s_dock, " & _
    " #tmpFR10.CUBE, " & _
    " #tmpFR10.Weight, " & _
    " LEFT(whs.dw_prodbpr.SubGroup,4),LEFT(whs.dw_prodbpr.SubGroup,3), " & _
    " IIF(#tmpBSQB.Act_BOH > (#tmpBSQB.s_dock + #tmpBSQB.non_s_dock), #tmpBSQB.Act_BOH, (#tmpBSQB.s_dock + #tmpBSQB.non_s_dock)) AS 'Calc' " & _
    "FROM #tmpFR10 " & _
    "LEFT JOIN whs.Focus_Prodtut ON #tmpFR10.tpnd =whs.Focus_Prodtut.Tpnd " _
    "LEFT JOIN whs.dw_prodbpr ONwhs.Focus_Prodtut.Tpnb = whs.dw_prodbpr.Tpnb " _
    "LEFT JOIN #tmpBSQB ON #tmpFR10.TPND =#tmpBSQB.TPND"
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    if with 2 ii , thats great just the pointer i needed.
    also came across case statement so will try both.

    thanks again xld.

Posting Permissions

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