Avatar of bounty457
bounty457

asked on 

SQL Mulitple Select Statemenst in one grid (SQL2008)

Hello,

i have one SQL Table in MS SQL 2008, and i want to have the results in one grid in different columns.
The result should be in Column Cost1 and column Cost2 and one Row.
In this Statement the result is in one Column and two Rows.

select SUM(costs) AS costs1 from costs where  ID = 1050
UNION All
select SUM(Amount) AS costs2 from costs  where (type = 1 or type = 4)and ID = 1050;

do you have any ideas how can i do this?
Thank you very much,
regards Bounty
Microsoft SQL Server 2008

Avatar of undefined
Last Comment
bounty457
SOLUTION
Avatar of Ganapathi
Ganapathi
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of bounty457
bounty457

ASKER

Hello,

Thank you very much. Both solutions works fine.

How is it possible to use the statement with many ID's.
The result should be written in one separate row for each ID.
Is it possible to us a loop.
The Id's are in second SQL table
The Tablename is CustID, and the Column name is ID.

regards bounty
ASKER CERTIFIED SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of bounty457
bounty457

ASKER

Thank you very much,

it works fine.

Regards Bounty
Microsoft SQL Server 2008
Microsoft SQL Server 2008

Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the Always On technologies and support for unstructured data types.

50K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo