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 |
bulubuk1976
Starting Member
24 Posts |
Posted - 2008-03-28 : 08:20:21
|
How can you have a 3rd field where you compare field1 and field2. If field1 and field 2 are identical, then place 1 else 0 in a view table? It is not accepting a CASE statement.Thanks for the help. |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-03-28 : 08:21:35
|
show us the statement you've triedEm |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-03-28 : 08:23:13
|
selectfld1 ,fld2 ,fld3 = case when fld1 = fld2 then 1 else 0 endfrom tblDecide what you wanty to do with nulls.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-28 : 08:24:42
|
Are you trying to make a calculated column?Try putting extra paranthesises around the (complete statement). E 12°55'05.25"N 56°04'39.16" |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-28 : 08:25:56
|
Sounds stupid, but are you really using SQL Server?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
bulubuk1976
Starting Member
24 Posts |
Posted - 2008-03-28 : 08:52:08
|
Here is my code. Basically it is a view table composed of 2 views.SELECT dbo.VIEW1.Den, dbo.VIEW2.Den AS Den2, CASE WHEN Den = Den2 THEN 1 ELSE 0 END AS Den3FROM dbo.VIEW1 CROSS JOIN dbo.VIEW2I am getting Ambigous Column Name 'Den' error. Thanks! |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2008-03-28 : 08:55:35
|
SELECT dbo.VIEW1.Den, dbo.VIEW2.Den AS Den2, CASE WHEN dbo.VIEW1.Den = dbo.VIEW2.Den THEN 1 ELSE 0 END AS Den3FROM dbo.VIEW1 CROSS JOINdbo.VIEW2 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-28 : 08:57:50
|
quote: Originally posted by singularity SELECT dbo.VIEW1.Den, dbo.VIEW2.Den AS Den2, CASE WHEN dbo.VIEW1.Den = dbo.VIEW2.Den THEN 1 ELSE 0 END AS Den3FROM dbo.VIEW1 CROSS JOINdbo.VIEW2
You can make that even more simple by using Alias:SELECT v1.Den, v2.Den AS Den2, CASE WHEN v1.Den = v2.Den THEN 1 ELSE 0 END AS Den3FROM dbo.VIEW1 v1 CROSS JOINdbo.VIEW2 v2 Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
|
|
|
|
|