I know this table is designed wrong for what I am doing but I hope I
can do it. I have a table like this.
Prod_A_Jan, Prod_A_Feb, Prod_B_Jan, Prod_B_Feb
I want a query that returns data like this (two rows of data)
"ProdA", Prod_A_Jan, Prod_A_Feb
"ProdB", Prod_B_Jan, Prod_B_Feb
I know two queries can get it but I want one. Any Help would be
great!!!
Sheila T. 3 1163
You can use a UNION query:
SELECT "ProdA", Prod_A_Jan AS Jan, Prod_A_Feb AS Feb
FROM MtTable
UNION ALL
SELECT "ProdB", Prod_B_Jan, Prod_B_Feb
FROM MtTable
--
Hope this helps.
Dan Guzman
SQL Server MVP
"George" <ge******@yahoo.com> wrote in message
news:e9**************************@posting.google.c om... I know this table is designed wrong for what I am doing but I hope I can do it. I have a table like this.
Prod_A_Jan, Prod_A_Feb, Prod_B_Jan, Prod_B_Feb
I want a query that returns data like this (two rows of data)
"ProdA", Prod_A_Jan, Prod_A_Feb "ProdB", Prod_B_Jan, Prod_B_Feb
I know two queries can get it but I want one. Any Help would be great!!!
Sheila T.
Hi,
try this one
SELECT "ProdA" AS Product, Prod_A_Jan AS Jan, Prod_A_Feb AS Feb
FROM TheTable
UNION
SELECT "ProdB" AS Product, Prod_B_Jan AS Jan, Prod_B_Feb AS Feb
FROM TheTable
-Jorgen
"George" <ge******@yahoo.com> skrev i en meddelelse
news:e9**************************@posting.google.c om... I know this table is designed wrong for what I am doing but I hope I can do it. I have a table like this.
Prod_A_Jan, Prod_A_Feb, Prod_B_Jan, Prod_B_Feb
I want a query that returns data like this (two rows of data)
"ProdA", Prod_A_Jan, Prod_A_Feb "ProdB", Prod_B_Jan, Prod_B_Feb
I know two queries can get it but I want one. Any Help would be great!!!
Sheila T.
Another approach using a derived table of literals which in most cases
eliminate multiple table scans :
SELECT val,
CASE val WHEN 'ProdA' THEN Prod_A_Jan
WHEN 'ProdB' THEN Prod_B_Jan
END,
CASE val WHEN 'ProdA' THEN Prod_A_Feb
WHEN 'ProdB' THEN Prod_B_Feb
END
FROM tbl
CROSS JOIN (
SELECT 'ProdA' UNION SELECT 'ProdB' ) D ( val ) ;
--
Anith This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Briniken |
last post by:
How can a SQL statement be written to return a specified range of
rows? For example:
-- tblContact
-- (
-- SSN char(9),
-- FirstName varchar(50),
-- LastName varchar(50)
-- )
-- This...
|
by: Ken |
last post by:
I wrote a function to use in queries that takes a date and adds or
subtracts a certain length time and then returns the new value. There
are times when my function needs to return Null values.
...
|
by: R.A. |
last post by:
Hi,
I have an web service method that accept an xml document and returns a
different xml document.
Based on the input xml I fill a dataset with information from a database.
If the dataset has...
|
by: jjturon |
last post by:
Can anyone help me??
I am trying to pass a Select Query variable to a table using Dlookup
and return the value to same select query but to another field.
Ex.
SalesManID ...
|
by: kilter |
last post by:
Anyone know of a routine that will return the number of rows and
columns in a matrix?
| |
by: Earl |
last post by:
I have all of my data operations in a separate library, so I'm looking for
what might be termed "best practices" on a return type from those classes.
For example, let's say I send an update from...
|
by: weird0 |
last post by:
The given should return A,B that is two rows because both
accountnames A and B have the same user_Id=1 but it is only returning
A when I performed the op. MessageBox.Show("AccountNames:" +...
|
by: thuythu |
last post by:
Please help me....
I used and Javascript to view the data. But when i click button open a popup windows, then select data and click save button. The popup close and return the main page, but the...
|
by: hailua |
last post by:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Collections;
public partial class UserDefinedFunctions...
|
by: roseate4amor |
last post by:
dear all,
i have a problem that i try to fix since the last few weeks.
i need to add a new data in microsoft office database using dataset in visual basic.
the problem is, when i insert new data...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |