Skip to Content
author's profile photo
Former Member

Multiple options within a query

I'm trying to create a new query within SBO where depending upon the outcome of a question will query against one set of data or the other.

Does anyone know where I've gone wrong with the code below?

SELECT dbo.OCRD.CardCode AS Code, dbo.OCRD.CardName AS Client, dbo.OCRD.CntctPrsn AS Contact, dbo.OCRD.Phone1 AS Phone, dbo.OCRD.Cellular AS Mobile, dbo.OCRD.CreditLine, dbo.OCRD.DebtLine, dbo.OCRD.Balance, '[%1]' as stuff

FROM dbo.OCRD INNER JOIN dbo.OSLP ON dbo.OCRD.SlpCode = dbo.OSLP.SlpCode

WHERE ((dbo.OCRD.CardType = 'C') OR (dbo.OCRD.CardType = 'L')) AND dbo.OCRD.Balance > (CASE WHEN [%1] = 'A' THEN dbo.OCRD.CreditLine ELSE dbo.OCRD.DebtLine END)

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • author's profile photo
    Former Member
    Feb 23, 2004 at 04:32 PM


    there are multiple errors inside this query - I just corrected SOME without testing, if it works:

    SELECT T0.CardCode AS 'Code', T0.CardName AS 'Client', T0.CntctPrsn AS 'Contact', T0.Phone1 AS 'Phone', T0.Cellular AS Mobile, T0.CreditLine, T0.DebtLine, T0.Balance FROM [dbo].[OCRD] T0 INNER JOIN [dbo].[OSLP] T1 ON T0.SlpCode = T1.SlpCode WHERE ((T0.CardType = 'C') OR (T0.CardType = 'L')) AND T0.Balance > (CASE '[%1]' WHEN 'A' THEN T0.CreditLine ELSE T0.DebtLine END) for browse

    I guess the query doesn't work like you want it to in this state. Do you really need the join? Just try it with two variables - one for CreditLine and one for DebitLine - should be easier.

    If you've got further questions according to correct syntax, just google for "Transact SQL".

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks for your help. The following was the code that in the end fixed the problem (although I had to create an additional table so as to be able to select the values I wanted). Simon.

      SELECT T0.CardCode AS 'BP Code', T0.CardName AS 'BP Name', T0.CntctPrsn AS 'Contact Person', T0.Phone1 AS 'Telephone 1', T0.Cellular AS 'Mobile Phone', T0.CreditLine AS 'Factor Credit Limit', T0.DebtLine AS 'Internal Credit Limit', T0.Balance AS 'Account Balance'

      FROM [dbo].[@CREDITPAYMENTLIMIT] T2, [dbo].[OSLP] T1 INNER JOIN [dbo].[OCRD] T0 ON T1.SlpCode = T0.SlpCode

      WHERE ((T0.CardType = 'C') OR (T0.CardType = 'L'))

      AND (CASE T2.Code WHEN 'Factor' THEN T0.CreditLine ELSE T0.DebtLine END) < T0.Balance

      AND t2.Code = '[%0]'