Skip to Content

query runs fine as sql query returns empty set when run in SBO

the following query works fine as sql query

if there is null value for @CrdSlp = '' the query returns all records

if @CrdSlp = '6' has value , the query returns recodrs where slpCode= 6

when i run this query in SBO and chose no slpCode in the query Selection Criteria the query odes not return any value

//* select * from oinv t1 */

* select * from ocrd t2 */

declare @startdate datetime , @EndDate datetime , @Sellet varchar, @ledtype varChar, @leaddate date, @kupa char , @CrdSlp varchar (4)

set @enddate =/* t1.docDate */ '[%1]' set @startdate = /* t1.docDate */ '[%0]'

set @CrdSlp = /* t2.slpCode */ '[%2]'

with tb1 as

( select t0.CardCode as CarsCode ,t0.CardName as CardName,convert(date,t0.CreateDate,103) as creDate,@EndDate as parm, datediff(day,@EndDate,t0.CreateDate)as datdif,t0.SlpCode as crdSlp, t0.U_LeadType as leadType,t0.U_Sellers as seller

from OCRD t0

where t0.CardName is Not null

and (datediff(day,t0.CreateDate,@EndDate))<=365

and t0.CreateDate<=@EndDate

and (@CrdSlp= ' ' or t0.SlpCode=@CrdSlp)


Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Dec 04, 2017 at 07:18 AM


    When you run the query in B1, and you leave the parameter empty, it will not pass a NULL value to that parameter, but instead it will pass a zero-length string (''). Please try to adapt the last line from:

    and (@CrdSlp= ' ' or t0.SlpCode=@CrdSlp)


    and ISNULL(t0.SlpCode, '') = @CrdSlp



    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.