School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,121 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,959 people online right now. Registration is fast and FREE... Join Now!




How do I merge two different results in Sql-server 2005

 

How do I merge two different results in Sql-server 2005, How do I merge the two results?

Torti

24 Jun, 2009 - 02:51 AM
Post #1

New D.I.C Head
*

Joined: 23 Jun, 2009
Posts: 3

CODE

insert into tbl_AllUsers(

select count(*)Total_Notification_Users  from accalert.TBL_AANSCUSTOMERS WHERE
(datecreated between '02/28/2009' and '04/01/2009')and(EMAIL_ADDR1 IS NOT NULL OR LEN(EMAIL_ADDR1)<3)

select count(*) as Total_SMS_Users from
accalert.TBL_AANSCUSTOMERS
where
(datecreated between '02/28/2009' and '04/01/2009'
) and (EMAIL_ADDR1 IS NOT NULL OR LEN(EMAIL_ADDR1) < 3) and SMS_PERMISSION=1
)

when run independently, the execute.
I need a merged result so I could display it on an ASP.NET web form.
Thanks in advance.

User is offlineProfile CardPM
+Quote Post


xerxes333

RE: How Do I Merge Two Different Results In Sql-server 2005

24 Jun, 2009 - 05:59 AM
Post #2

D.I.C Regular
Group Icon

Joined: 5 Jul, 2007
Posts: 454



Thanked: 24 times
Dream Kudos: 25
My Contributions
UNION
http://www.w3schools.com/sql/sql_union.asp
User is offlineProfile CardPM
+Quote Post

kzimmerm

RE: How Do I Merge Two Different Results In Sql-server 2005

25 Jun, 2009 - 11:32 AM
Post #3

D.I.C Head
**

Joined: 8 Feb, 2009
Posts: 67



Thanked: 3 times
My Contributions
UNION is the way to go. You have to make sure your columns in both selects produce the same result set.

then it is as simple as
CODE


select blah, blah from sometable1
union
select blah, blah from sometable2



Kurt

User is offlineProfile CardPM
+Quote Post

Torti

RE: How Do I Merge Two Different Results In Sql-server 2005

29 Jun, 2009 - 01:25 AM
Post #4

New D.I.C Head
*

Joined: 23 Jun, 2009
Posts: 3

QUOTE(kzimmerm @ 25 Jun, 2009 - 11:32 AM) *

UNION is the way to go. You have to make sure your columns in both selects produce the same result set.

then it is as simple as
CODE


select blah, blah from sometable1
union
select blah, blah from sometable2



Kurt

Thanks... I really want to insert the value of "my" two Select statements into 2 columns in a different table, then display the "new" table, using another Select statement.
Thanks for your help once more...

QUOTE(Torti @ 24 Jun, 2009 - 02:51 AM) *

CODE

insert into tbl_AllUsers(

select count(*)Total_Notification_Users  from accalert.TBL_AANSCUSTOMERS WHERE
(datecreated between '02/28/2009' and '04/01/2009')and(EMAIL_ADDR1 IS NOT NULL OR LEN(EMAIL_ADDR1)<3)

select count(*) as Total_SMS_Users from
accalert.TBL_AANSCUSTOMERS
where
(datecreated between '02/28/2009' and '04/01/2009'
) and (EMAIL_ADDR1 IS NOT NULL OR LEN(EMAIL_ADDR1) < 3) and SMS_PERMISSION=1
)

when run independently, the execute.
I need a merged result so I could display it on an ASP.NET web form.
Thanks in advance.



QUOTE(Torti @ 24 Jun, 2009 - 02:51 AM) *

CODE

insert into tbl_AllUsers(

select count(*)Total_Notification_Users  from accalert.TBL_AANSCUSTOMERS WHERE
(datecreated between '02/28/2009' and '04/01/2009')and(EMAIL_ADDR1 IS NOT NULL OR LEN(EMAIL_ADDR1)<3)

select count(*) as Total_SMS_Users from
accalert.TBL_AANSCUSTOMERS
where
(datecreated between '02/28/2009' and '04/01/2009'
) and (EMAIL_ADDR1 IS NOT NULL OR LEN(EMAIL_ADDR1) < 3) and SMS_PERMISSION=1
)

when run independently, the execute.
I need a merged result so I could display it on an ASP.NET web form.
Thanks in advance.



QUOTE(Torti @ 24 Jun, 2009 - 02:51 AM) *

CODE

insert into tbl_AllUsers(

select count(*)Total_Notification_Users  from accalert.TBL_AANSCUSTOMERS WHERE
(datecreated between '02/28/2009' and '04/01/2009')and(EMAIL_ADDR1 IS NOT NULL OR LEN(EMAIL_ADDR1)<3)

select count(*) as Total_SMS_Users from
accalert.TBL_AANSCUSTOMERS
where
(datecreated between '02/28/2009' and '04/01/2009'
) and (EMAIL_ADDR1 IS NOT NULL OR LEN(EMAIL_ADDR1) < 3) and SMS_PERMISSION=1
)

when run independently, the execute.
I need a merged result so I could display it on an ASP.NET web form.
Thanks in advance.



Thanks... I really want to insert the value of "my" two Select statements into 2 columns in a different table, then display the "new" table, using another Select statement.
Thanks for your help once more...

User is offlineProfile CardPM
+Quote Post

kzimmerm

RE: How Do I Merge Two Different Results In Sql-server 2005

29 Jun, 2009 - 09:11 AM
Post #5

D.I.C Head
**

Joined: 8 Feb, 2009
Posts: 67



Thanked: 3 times
My Contributions
what database platform are you using?

There are several solutions to your issues based upon the database platform.

Kurt

User is offlineProfile CardPM
+Quote Post

Torti

RE: How Do I Merge Two Different Results In Sql-server 2005

6 Jul, 2009 - 06:51 AM
Post #6

New D.I.C Head
*

Joined: 23 Jun, 2009
Posts: 3

QUOTE(kzimmerm @ 29 Jun, 2009 - 09:11 AM) *

what database platform are you using?

There are several solutions to your issues based upon the database platform.

Kurt

I use Microsoft Sql - server 2005. Thanks
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 01:54PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month