May 6, 2011 at 10:59 am
I'm trying to do the following in SQL 2008
.....
where
if @openorder>1 then o.openorder=1 or o.openorder =0
else
o.openorder=@openorder
endif
Can this be done? if so how can I do it
May 6, 2011 at 11:02 am
Crap code too!!!!!!!!!!:w00t:
May 6, 2011 at 11:04 am
Like this:
SELECT openorder
FROM @Table
WHERE
openorder =
( CASE WHEN @openorder > 1 THEN 1
ELSE @openorder
END )
OR
openorder =
( CASE WHEN @openorder > 1 THEN 0
ELSE @openorder
END )
May 6, 2011 at 11:13 am
ColdCoffee (5/6/2011)
Like this:{CRAP CODE}
DECLARE @openorder INT
SET @openorder = 2
DECLARE @tbl TABLE (openorder INT)
INSERT INTO @tbl (openorder)
SELECT 0
UNION ALL
SELECT 1
UNION ALL
SELECT 2
--UNION ALL
SELECT * FROM @tbl o
WHERE
CASE WHEN @openorder > 1 THEN o.openorder IN ( 0 ,1 )
ELSE o.openorder=@openorder
END
Msg 156, Level 15, State 1, Line 21
Incorrect syntax near the keyword 'IN'.
May 6, 2011 at 11:19 am
DECLARE @openorder INT
SET @openorder = 2
DECLARE @tbl TABLE (openorder INT)
INSERT INTO @tbl (openorder)
SELECT 0
UNION ALL
SELECT 1
UNION ALL
SELECT 2
UNION ALL
SELECT 3
UNION ALL
SELECT 4
--UNION ALL
SELECT
*
FROM
@tbl o
WHERE
1 = CASE WHEN @openorder > 1
AND o.openorder IN ( 0 , 1 ) THEN 1
ELSE --0
CASE WHEN o.openorder = @openorder THEN 1
ELSE 0
END
END
May 6, 2011 at 11:20 am
Ninja's_RGR'us (5/6/2011)
ColdCoffee (5/6/2011)
Like this:{CRAP CODE}
Msg 156, Level 15, State 1, Line 21
Incorrect syntax near the keyword 'IN'.
Fixed the code 🙂
May 6, 2011 at 11:20 am
Ninja's_RGR'us (5/6/2011)
Crap code too!!!!!!!!!!:w00t:
😛
May 6, 2011 at 11:26 am
ColdCoffee (5/6/2011)
Ninja's_RGR'us (5/6/2011)
Crap code too!!!!!!!!!!:w00t:😛
ya but you beat me to it :w00t:
So somehow it must be your fault :hehe:
May 6, 2011 at 11:28 am
Thanks guys - this works
1 = CASE WHEN @openorder > 1 AND o.openorder IN ( 0 , 1 ) THEN 1
ELSE --0
CASE WHEN o.openorder = @openorder THEN 1
ELSE 0
END END
May 6, 2011 at 11:33 am
Ninja's_RGR'us (5/6/2011)
ColdCoffee (5/6/2011)
Ninja's_RGR'us (5/6/2011)
Crap code too!!!!!!!!!!:w00t:😛
ya but you beat me to it :w00t:
So somehow it must be your fault :hehe:
Surrendering, Master :w00t: 😛
May 6, 2011 at 11:35 am
Alright... let's just call it friday afternoon and time to go home.
l8r! ;-):-P:-D:hehe::smooooth:
May 6, 2011 at 11:53 am
Ninja's_RGR'us (5/6/2011)
Alright... let's just call it friday afternoon and time to go home.l8r! ;-):-P:-D:hehe::smooooth:
Friday afternoon, and going HOME ?? :w00t::-D
May 6, 2011 at 1:39 pm
ColdCoffee (5/6/2011)
Ninja's_RGR'us (5/6/2011)
Alright... let's just call it friday afternoon and time to go home.l8r! ;-):-P:-D:hehe::smooooth:
Friday afternoon, and going HOME ?? :w00t::-D
It's already 3:30 PM here. Was about time I got home!
May 9, 2012 at 10:03 am
So, did BIGC2269 get what he needed? BIGC2269, what was the issue?
I found this worked.
DECLARE @openorder INT
SET @openorder = 2
DECLARE @Table TABLE (openorder INT)
INSERT INTO @Table (openorder)
SELECT 0
UNION ALL
SELECT 1
UNION ALL
SELECT 2
UNION ALL
SELECT 3
UNION ALL
SELECT 4
--UNION ALL
SELECT openorder
FROM @Table
WHERE
openorder =
( CASE WHEN @openorder > 1 THEN 1
ELSE @openorder
END )
OR
openorder =
( CASE WHEN @openorder > 1 THEN 0
ELSE @openorder
END )
This did not work.
DECLARE @openorder INT
SET @openorder = 2
DECLARE @tbl TABLE (openorder INT)
INSERT INTO @tbl (openorder)
SELECT 0
UNION ALL
SELECT 1
UNION ALL
SELECT 2
UNION ALL
SELECT 3
UNION ALL
SELECT 4
--UNION ALL
SELECT
*
FROM
@tbl o
WHERE
1 = CASE WHEN @openorder > 1
AND o.openorder IN ( 0 , 1 ) THEN 1
ELSE --0
CASE WHEN o.openorder = @openorder THEN 1
ELSE 0
END
END
--Quote me
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply