Data to be displayed 
Author Message
 Data to be displayed

I have a table with following data:
ID      RuleID  Answer  Date
31      1       yes     7/24/02
31      2       yes     7/24/02
31      3       yes     7/24/02
31      4       no      7/24/02
32      1       yes     7/27/02
32      2       no      7/24/02
32      3       yes     7/24/02
32      4       yes     7/24/02

I need to display like this:
31 yes yes yes no
32 yes no yes yes
I do I do this?



Fri, 06 Jan 2006 20:09:03 GMT
 Data to be displayed

Hi
-----------
CREATE TABLE TABLE1 (
        [id] [char] (10) NULL ,
        [ruleind] [int] NULL ,
        [answer] [char] (10) NULL ,
        [date] [datetime] NULL
)

-----------------
INSERT INTO TABLE1 VALUES (31,1,'NO,'7/1/03')
INSERT INTO TABLE1 VALUES (31,2,'YES,'7/1/03')
INSERT INTO TABLE1 VALUES (31,3,'NO,'7/1/03')
INSERT INTO TABLE1 VALUES (31,4,'YES,'7/1/03')
INSERT INTO TABLE1 VALUES (32,1,'NO,'7/1/03')
INSERT INTO TABLE1 VALUES (32,2,'YES,'7/1/03')
INSERT INTO TABLE1 VALUES (32,3,'YES,'7/1/03')
INSERT INTO TABLE1 VALUES (32,4,'NO,'7/1/03')

---

SELECT id, MIN(CASE NBR WHEN 1 THEN answer END) v1,
    MIN(CASE NBR WHEN 2 THEN answer END) v2,
    MIN(CASE NBR WHEN 3 THEN answer END) v3,
    MIN(CASE NBR WHEN 4 THEN answer END) v4
FROM (SELECT id, ANSWER,
              (SELECT ruleind
            FROM table1 a
            WHERE a.id = table1.id AND
                 a.ruleind = table1.ruleind)
      FROM TABLE1) KAN (ID, ANSWER, NBR)
GROUP BY ID

===
will work

kannan

Quote:
>-----Original Message-----
>I have a table with following data:
>ID  RuleID  Answer  Date
>31          1       yes     7/24/02
>31  2       yes     7/24/02
>31  3       yes     7/24/02
>31  4       no      7/24/02
>32  1       yes     7/27/02
>32  2       no      7/24/02
>32  3       yes     7/24/02
>32  4       yes     7/24/02

>I need to display like this:
>31 yes yes yes no
>32 yes no yes yes
>I do I do this?
>.



Fri, 06 Jan 2006 21:08:24 GMT
 Data to be displayed
I have some T-SQL programming question regarding u're
code.  Frist of all, some of your input variable needs "'"
at either end of "Yes and No".  But what i'm confused is
your 2 lines of code.

1.  Min(Case NBR When 1 Then Answer End) v1,

what does Min() function do in this case and where have u
stated the NBR???

2.  FROM TABLE1) KAN (ID, ANSWER, NBR)
What is KAN, i can't seem to find that line of code in my
T-SQL book?

Please bear in mind, i'm new at programming using T-SQL,
and i would like to understand your code.

Quote:
>-----Original Message-----

>Hi
>-----------
>CREATE TABLE TABLE1 (
>    [id] [char] (10) NULL ,
>    [ruleind] [int] NULL ,
>    [answer] [char] (10) NULL ,
>    [date] [datetime] NULL
>)

>-----------------
>INSERT INTO TABLE1 VALUES (31,1,'NO,'7/1/03')
>INSERT INTO TABLE1 VALUES (31,2,'YES,'7/1/03')
>INSERT INTO TABLE1 VALUES (31,3,'NO,'7/1/03')
>INSERT INTO TABLE1 VALUES (31,4,'YES,'7/1/03')
>INSERT INTO TABLE1 VALUES (32,1,'NO,'7/1/03')
>INSERT INTO TABLE1 VALUES (32,2,'YES,'7/1/03')
>INSERT INTO TABLE1 VALUES (32,3,'YES,'7/1/03')
>INSERT INTO TABLE1 VALUES (32,4,'NO,'7/1/03')

>---

>SELECT id, MIN(CASE NBR WHEN 1 THEN answer END) v1,
>    MIN(CASE NBR WHEN 2 THEN answer END) v2,
>    MIN(CASE NBR WHEN 3 THEN answer END) v3,
>    MIN(CASE NBR WHEN 4 THEN answer END) v4
>FROM (SELECT id, ANSWER,
>              (SELECT ruleind
>            FROM table1 a
>            WHERE a.id = table1.id AND
>                 a.ruleind = table1.ruleind)
>      FROM TABLE1) KAN (ID, ANSWER, NBR)
>GROUP BY ID

>===
>will work

>kannan
>>-----Original Message-----
>>I have a table with following data:
>>ID      RuleID  Answer  Date
>>31      1       yes     7/24/02
>>31      2       yes     7/24/02
>>31      3       yes     7/24/02
>>31      4       no      7/24/02
>>32      1       yes     7/27/02
>>32      2       no      7/24/02
>>32      3       yes     7/24/02
>>32      4       yes     7/24/02

>>I need to display like this:
>>31 yes yes yes no
>>32 yes no yes yes
>>I do I do this?
>>.

>.



Fri, 06 Jan 2006 23:38:27 GMT
 Data to be displayed
Well,
I was trying to give scripts to create the requirments
asked for.
Typo it was re: yes and no
Thanks.

Re: T-SQL Programming question, Kan is a table alias.
Rest is all self explainatory.

Kn

Quote:
>-----Original Message-----
>I have some T-SQL programming question regarding u're
>code.  Frist of all, some of your input variable
needs "'"
>at either end of "Yes and No".  But what i'm confused is
>your 2 lines of code.

>1.  Min(Case NBR When 1 Then Answer End) v1,

>what does Min() function do in this case and where have u
>stated the NBR???

>2.  FROM TABLE1) KAN (ID, ANSWER, NBR)
>What is KAN, i can't seem to find that line of code in my
>T-SQL book?

>Please bear in mind, i'm new at programming using T-SQL,
>and i would like to understand your code.

>>-----Original Message-----

>>Hi
>>-----------
>>CREATE TABLE TABLE1 (
>>        [id] [char] (10) NULL ,
>>        [ruleind] [int] NULL ,
>>        [answer] [char] (10) NULL ,
>>        [date] [datetime] NULL
>>)

>>-----------------
>>INSERT INTO TABLE1 VALUES (31,1,'NO,'7/1/03')
>>INSERT INTO TABLE1 VALUES (31,2,'YES,'7/1/03')
>>INSERT INTO TABLE1 VALUES (31,3,'NO,'7/1/03')
>>INSERT INTO TABLE1 VALUES (31,4,'YES,'7/1/03')
>>INSERT INTO TABLE1 VALUES (32,1,'NO,'7/1/03')
>>INSERT INTO TABLE1 VALUES (32,2,'YES,'7/1/03')
>>INSERT INTO TABLE1 VALUES (32,3,'YES,'7/1/03')
>>INSERT INTO TABLE1 VALUES (32,4,'NO,'7/1/03')

>>---

>>SELECT id, MIN(CASE NBR WHEN 1 THEN answer END) v1,
>>    MIN(CASE NBR WHEN 2 THEN answer END) v2,
>>    MIN(CASE NBR WHEN 3 THEN answer END) v3,
>>    MIN(CASE NBR WHEN 4 THEN answer END) v4
>>FROM (SELECT id, ANSWER,
>>              (SELECT ruleind
>>            FROM table1 a
>>            WHERE a.id = table1.id AND
>>                 a.ruleind = table1.ruleind)
>>      FROM TABLE1) KAN (ID, ANSWER, NBR)
>>GROUP BY ID

>>===
>>will work

>>kannan
>>>-----Original Message-----
>>>I have a table with following data:
>>>ID  RuleID  Answer  Date
>>>31          1       yes     7/24/02
>>>31  2       yes     7/24/02
>>>31  3       yes     7/24/02
>>>31  4       no      7/24/02
>>>32  1       yes     7/27/02
>>>32  2       no      7/24/02
>>>32  3       yes     7/24/02
>>>32  4       yes     7/24/02

>>>I need to display like this:
>>>31 yes yes yes no
>>>32 yes no yes yes
>>>I do I do this?
>>>.

>>.

>.



Sat, 07 Jan 2006 02:41:54 GMT
 
 [ 4 post ] 

 Relevant Pages 

1. Display Time Only (hh:mm:ss AM - format)

2. Time (hr:min) display - NOT AM/PM

3. Display across - display data Horizontly -

4. Help: Displaying the data in data entry format

5. asp cannot insert data to sql server 2000, but can select data to display

6. Display data on DBGrid without needing Data Control?

7. error ORA-01855: AM/A.M. or PM/P.M. required

8. Use of @am, Am I dumb?

9. Busy Day = Slowdown from 12 AM - 5 AM

10. I am getting this message when i am tring to export or import anything using

11. Sr. Data Warehousing Director - Dallas, TX 9/14/98 11:46:06 AM

12. Oracle 8i lite, I can't enter data into a table, ( newbie I am )


 
Powered by phpBB® Forum Software