Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 parse value from field

Author  Topic 

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2009-08-03 : 13:48:09
I have a field that contains -

3x8, 4/0 50#

The length/format is inconsitent for me to use Left, Right, Substr etc.

What I need to do is evaluate the value after /.

If its 0 return 1.
If its > 0 return 2.

Can anyone help with this? thanks.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-03 : 14:07:29
And it is always existing or can it happen that no slash is in the field?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2009-08-03 : 14:12:22
It will always have a / then a number.

So it may be -

3x8, 4/4 50#
3x8, 4/1 50#
3x8, 4/0 50#
8x11, 4/0 50#

etc.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-08-03 : 14:20:50
[code]DECLARE @t TABLE(
col1 VARCHAR(25)
)

INSERT @t
SELECT '3x8, 4/0 50#'
UNION ALL
SELECT '3x8, 400 5/0#'
UNION ALL
SELECT '3x8, 400 5/1#'

SELECT CASE substring(col1,charindex('/',col1) + 1,1)
WHEN 0
THEN 1
ELSE 2
END AS [col1]
FROM @t[/code]
Go to Top of Page

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2009-08-03 : 14:27:14
So I could take this and do somthing like this (which does not work as written)?

Basically I want to pass in the value (product) to a function and return 1 or 2.



CREATE FUNCTION Get_Sides
(
@Product VARCHAR(20)
)
RETURNS Int
AS
BEGIN
RETURN (
SELECT CASE substring(col1,charindex('/',col1) + 1,1)
WHEN 0
THEN 1
ELSE 2
END AS [col1]
FROM @Product
)
END

Go to Top of Page

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2009-08-03 : 14:48:00
I figured it out. Thanks for all your help.



CREATE FUNCTION Get_Sides
(
@Product VARCHAR(20)
)
RETURNS Int
AS
BEGIN
RETURN (
SELECT CASE substring(@Product,charindex('/',@Product) + 1,1)
WHEN 0
THEN 1
ELSE 2
END AS [col1]
)
END



Go to Top of Page
   

- Advertisement -