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.
| Author |
Topic |
|
wndrboy2k3
Starting Member
37 Posts |
Posted - 2008-04-30 : 00:12:55
|
| Hello,Brand new to the forum and I'm hoping I can get some help from you guys here.I'm not sure how I would go abouts doing this but I have a table that has a list of my Inventory and it looks like this.Product InventoryModems 10I want a way (whether it be a stored procedure or view) to display instead of the value of 10, that if there Inventory has a value greater than 0 then to return a boolean of YES, TRUE, or 1. How would I go abouts doing that?Any help would be greatly appreciated.WNDRBOY. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-30 : 02:31:23
|
SELECT Product, CASE WHEN Inventory > 0 THEN 'Yes' ELSE 'No' ENDFROM Table1 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-04-30 : 09:07:45
|
| If you want 1 or 0,SELECT Product, cast(Inventory as bit)FROM Table1MadhivananFailing to plan is Planning to fail |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-04-30 : 09:12:21
|
| Stick with BIT. It is more standard and doesn't force formatting into your data. Most front-end applications and clients that work with SQL Server will translate a BIT column to a boolean.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
wndrboy2k3
Starting Member
37 Posts |
Posted - 2008-04-30 : 12:47:27
|
| You guys are amazing! Both solutions worked, but it also brings up more questions. I tried to figure out a way to integrate both solutions (yeah newbie) and have done lots of research on google but have had no luck.Let's say I want the ">0" to be a ">10" but want it to return a bit. No matter what i do i keep getting "INCORRECT SYNTAX NEAR AS" or "SELECT" or wherever the syntax moves to depending on my attempts. Now, let me bring in another layer of complications.PRODUCT INVENTORY COLOURMODEM 10 blackMODEM2 5 WHITECan i set different rules for the colour column being returned? Like for black i want the rule to be >5 return as (1) and for white ">10" return as (1). I certainly don't want you guys to feel like i'm getting you to write code for me, i'm just learning so if you can point me in the right direction, I would really appreciate it. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-30 : 12:54:21
|
| Add the extra condition also inside CASE WHEN |
 |
|
|
|
|
|