CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Location
    Poland
    Posts
    278

    What Query for some issue ?

    Hello

    I have been writting a DataBase Application ... and I need to creat an query.
    I'm not familar with SQL too much.

    I think that the best solution to describe my problem will be picture as follows:
    Attached Images Attached Images

  2. #2
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: What Query for some issue ?

    This is a pivoting functionality. Achieving it depends on the database you use. Can you mention it?
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  3. #3
    Join Date
    Jul 1999
    Location
    Poland
    Posts
    278

    Re: What Query for some issue ?

    Quote Originally Posted by hspc
    This is a pivoting functionality. Achieving it depends on the database you use. Can you mention it?
    I use MS SQL Server 2000

  4. #4
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: What Query for some issue ?

    Unfortunately, MS SQL Server 2000 did not support pivoting.
    However you can try tips mentioned in these links to overcome this issue:
    http://www.mssqltips.com/tip.asp?tip=937
    http://www.dotnetjunkies.com/WebLog/...23/133383.aspx
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  5. #5
    Join Date
    Jul 1999
    Location
    Poland
    Posts
    278

    Re: What Query for some issue ?

    Thanks a lot.
    There are very usefull links. Unfortunately I'm not able to rate your perfect post.

    by the way
    please find answer below for my issue
    Code:
    USE ABBMeasureHistory
    
    SELECT T1.X,
    SUM(CASE T2.Sensor WHEN 4 THEN T2.Val ELSE 0 END) AS Sensor4,
    SUM(CASE T2.Sensor WHEN 5 THEN T2.Val ELSE 0 END) AS Sensor5,
    SUM(CASE T2.Sensor WHEN 6 THEN T2.Val ELSE 0 END) AS Sensor6,
    SUM(CASE T2.Sensor WHEN 7 THEN T2.Val ELSE 0 END) AS Sensor7
    FROM Table_1 T1, Table_2 T2
    WHERE T1.id_t1 = T2.id_t1 AND T1.id_t1=1001
    GROUP BY T1.X
    GO
    The more I learn SQL the more I am impressed by SQL.
    Last edited by Andrzej; August 24th, 2008 at 03:29 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured