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 |
|
phil3061
Starting Member
4 Posts |
Posted - 2012-04-25 : 11:44:22
|
| Hello,I have a table I'm trying to query. Every time a form is submitted there are 26 rows associated with that form in the table. There is 1 column named "vcObjectName" that if it has a value of "New York Target", I need to look in the column "vcAnswerValue" to see if it was answered "Yes" or "No". Can I query it so that it outputs all 26 rows associated with that form to have a new column with "Yes" or "No" listed on every row depending on the answer from the "vcAnswerValue" column.Thanks,Phil |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-04-25 : 12:11:02
|
| I'm not 100% sure I'm following what you want to do. Cant you post DDL, DML and expected output?Here are a couple of links that can help you with that if you are not familar with those terms:http://www.sqlservercentral.com/articles/Best+Practices/61537/http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
phil3061
Starting Member
4 Posts |
Posted - 2012-04-25 : 13:11:40
|
| I actually don't have access to it. I only have access to the view. Basically, I'm trying to create a computed column by reading 2 different columns in the array. So every 26 rows will be 1 array. Within each array, can I create a computed column that looks at column "vcObjectName" to find what row has the value "New York Target", once that row is determined, go to column "vcAnswerValue" and grab the value in that same row that "New York Target" is on. Then in the calculated column, attach to all 26 rows "yes" or "no".Table querying"vcName", "vcObjectName" , "vcAnswerValue""Bob" , "New York Target", "Yes""Bob" , "Q1" , "No""Bob" , "Q2" , "No"Expected OutputTable querying"vcName", "vcObjectName" , "vcAnswerValue", "Calculated Column""Bob" , "New York Target", "Yes" , "Yes""Bob" , "Q1" , "No" , "Yes""Bob" , "Q2" , "No" , "Yes"Sorry, I know the formatting is off, but this hopefully gives you an idea of what I'm trying to accomplish. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-04-25 : 14:17:25
|
selectt1.vcName,t1.vcObjectName,t1.vcAnswerValue,dt.CalcColumnfrom table1 as t1join (select distinct vcName, vcAnswerValue as CalcColumn from table where vcObjectName='New York Target')dton dt.vcName=t1.vcName No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
phil3061
Starting Member
4 Posts |
Posted - 2012-04-25 : 17:31:30
|
| AWESOME....that's exactly what I needed. THANK YOU!!! |
 |
|
|
|
|
|
|
|