Article View: bit.databases.mssql-l
Article #2017Re: Building SQL Query???
From: Baxter, Geoff
Date: Tue, 04 Apr 1995 00:00
Date: Tue, 04 Apr 1995 00:00
62 lines
2442 bytes
2442 bytes
You can do this using Transact, however it is not very elegent.
Try creating 2 views:
Create View View1 as Select * from Table where Col2 = 1
Create View View2 as Select * from Table where Col2 = 2
And the select from the views:
Select View1.Col1, Sum(View1.Col3), Sum(View2.Col3)
From View1, View2
Where View1.Col1 *= View2.Col1
group by View1.Col1
Geoff Baxter
Telecom Australia
(03) 684-5438.
GBaxter@VACCNORQ.Telecom.com.au
----------
From: MSSQL-L
To: Multiple recipients of list MSSQL-L
Subject: Building SQL Query???
Date: Monday, 3 April 1995 3:26PM
Pardon me for sounding like a newbie here, but I am really stuck
with trying to write a SQL statement (listed below). I am trying to do
this in C++ currently to go against a MSSQL Server so I am stuck (as far
as I know with Transact). If someone has other suggestions as to another
product that would give me additional ability with my SQL statements, I
would be more than all ears..as it were. Many TIAs for anyone that could
help or provide guidance on this.
================
Using Transact SQL, I need to return a table like this:
====================================
FIELDA FIELDB FIELDC
====================================
B 100 150
C 210 350
D 145 0
====================================
from a table similar to the one listed below. This selects the
value of Col1 and provides the sum of Col3 into either FieldB or FieldC
based on the value of Col2 (i.e. if Col2 is 1 then the Sum of Col3 into
fieldB...etc..)
Table...
===============================
Col1 Col2 Col3
===============================
B 1 100
B 2 150
C 1 210
C 2 350
D 1 145
===============================
John Murray
jmurray@dnasunnet.dna.mci.com
Technical Details
Message-ID:
<2F819DC7@msmailv0.telecom.com.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f6611,2f52e0a1fb0e2fbd X-Google-Attributes: gidf6611,public From: "Baxter, Geoff" <GBaxter@VACCNORQ.TELECOM.COM.AU> Subject: Re: Building SQL Query??? Date: 1995/04/04 Message-ID: <2F819DC7@msmailv0.telecom.com.au> X-Deja-AN: 100850613 sender: Microsoft SQL Server Discussion List comments: Gated by NETNEWS@AUVM.AMERICAN.EDU encoding: 63 TEXT newsgroups: bit.databases.mssql-l x-mailer: Microsoft Mail V3.0