CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    [RESOLVED] Help with the SQL Query

    Good Day All

    I have the Following SP

    Code:
    ALTER PROC GET_BASED_PATTERN
    (
    @SUBJECT VARCHAR(30),
    @Pattern  nvarchar(128) output 
    )
    AS
    SET @Pattern = (SELECT TOP 1 TERM.[CYCLETEMPLATES]FROM tbl_term TERM 
    INNER JOIN dbo.TBL_ACTV v
    on TERM.ID = V.TERM
    INNER JOIN  DBO._Subjects S
    ON V.TERM = S.[LEVEL]
    WHERE CODE = @SUBJECT)
    SELECT 
    CASE 
    WHEN LEN(@Pattern) > 1 THEN @Pattern
    ELSE '00000000'
    END
    It returns

    Code:
    00000000 and Null
    and NUll at the Bottom if the len is not greater than 1. i want it to return 00000000 if its like that.

    Thank you
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Help with the SQL Query

    If I understand you correct then you want it to return 00000000 both if LEN(@Pattern) is less then 1 and @Pattern is null?

    There are many ways to do this, and depending on how "pretty" you want the solution. But the easiest way would properly be to just assign a value of '' if your pattern is null, so something like this:

    Code:
    IF @Pattern IS NULL
     SET @Pattern = ''
    
    SELECT 
    CASE 
    WHEN LEN(@Pattern) > 1 THEN @Pattern
    ELSE '00000000'
    END

  3. #3
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    Re: Help with the SQL Query

    Thank you for your Help. i did it this way and its working.


    Code:
    ALTER PROC GET_BASED_PATTERN
    (
    @SUBJECT VARCHAR(30),
    @Pattern  nvarchar(128) output 
    )
    AS
    SET @Pattern = (SELECT TOP 1 TERM.[CYCLETEMPLATES]
    FROM tbl_term TERM
    INNER JOIN dbo.TBL_ACTV v 
    on TERM.ID = V.TERM
    INNER JOIN  DBO._Subjects S  ON 
    V.TERM = S.[LEVEL]
    WHERE CODE = @SUBJECT)
    IF @Pattern is null Set @Pattern = '00000000'Select @Pattern
    Thank you
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

  4. #4
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Help with the SQL Query

    Quote Originally Posted by vuyiswam View Post
    Thank you for your Help. i did it this way and its working.


    Code:
    ALTER PROC GET_BASED_PATTERN
    (
    @SUBJECT VARCHAR(30),
    @Pattern  nvarchar(128) output 
    )
    AS
    SET @Pattern = (SELECT TOP 1 TERM.[CYCLETEMPLATES]
    FROM tbl_term TERM
    INNER JOIN dbo.TBL_ACTV v 
    on TERM.ID = V.TERM
    INNER JOIN  DBO._Subjects S  ON 
    V.TERM = S.[LEVEL]
    WHERE CODE = @SUBJECT)
    IF @Pattern is null Set @Pattern = '00000000'Select @Pattern
    Thank you
    Well - that approach seem to violate your first listed example, but it might be because of a bug in the first.
    Because your first - the requirement was the pattern had to be larger then 1 in length so it had to be 2 characters or more.

  5. #5
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    Re: [RESOLVED] Help with the SQL Query

    I did the Count of a Length to check for Empty or Null
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

  6. #6
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: [RESOLVED] Help with the SQL Query

    Well yeah - but LEN() > 1 also means that 1 letter patterns would not be filtered, and thus constraint would catch more then just empty strings.
    I'd guess it should then be LEN() > 0 or >= 1, but I thought it was a restriction based on your ealier code that patterns with the length of 1 should also get a row of zeros

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured