|
-
March 4th, 2009, 09:54 AM
#1
[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
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."
-
March 5th, 2009, 12:01 AM
#2
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
-
March 5th, 2009, 01:05 AM
#3
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."
-
March 5th, 2009, 02:15 AM
#4
Re: Help with the SQL Query
 Originally Posted by vuyiswam
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.
-
March 5th, 2009, 02:19 AM
#5
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."
-
March 5th, 2009, 05:21 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|