SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Attach value to every row depending on answer
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

phil3061
Starting Member

4 Posts

Posted - 04/25/2012 :  11:44:22  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3829 Posts

Posted - 04/25/2012 :  12:11:02  Show Profile  Reply with Quote
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
Go to Top of Page

phil3061
Starting Member

4 Posts

Posted - 04/25/2012 :  13:11:40  Show Profile  Reply with Quote
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 Output
Table 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.
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8514 Posts

Posted - 04/25/2012 :  14:17:25  Show Profile  Visit webfred's Homepage  Reply with Quote
select
t1.vcName,
t1.vcObjectName,
t1.vcAnswerValue,
dt.CalcColumn
from table1 as t1
join (select distinct vcName, vcAnswerValue as CalcColumn from table where vcObjectName='New York Target')dt
on dt.vcName=t1.vcName


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

phil3061
Starting Member

4 Posts

Posted - 04/25/2012 :  17:31:30  Show Profile  Reply with Quote
AWESOME....that's exactly what I needed. THANK YOU!!!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000