Showing posts with label combine. Show all posts
Showing posts with label combine. Show all posts

Wednesday, March 28, 2012

Query - Join:

What type of Query should I use to combine two sets of data into the same
recordset. Note that none of the companies in TableA are the same as the
companies in TableB (distinct sets of data).
TableA
Company, Sales, Members
Table B
Company, Members, Vacation
Query Should Produce
Company, Sales, Members Vacations"William" <da@.northernit.net> wrote in message
news:ikoke.16188$tM3.4933@.twister.nyroc.rr.com...
> What type of Query should I use to combine two sets of data into the same
> recordset. Note that none of the companies in TableA are the same as the
> companies in TableB (distinct sets of data).
> TableA
> Company, Sales, Members
> Table B
> Company, Members, Vacation
> Query Should Produce
> Company, Sales, Members Vacations
>
If you know that they are definitely distinct, then you could simply do the
following:
INSERT dbo.TableA (Company, Sales, Members, Vacations)
SELECT Company, NULL, Members, Vacation
FROM dbo.TableB
Rick Sawtell
MCT, MCSD, MCDBA|||Are there any matching values between the two tables (e.g. Members)? If so,
the
following might work:
Select Coalesce(TableA.Company, TableB.Company) As Company
, TableA.Sales
, Coalesce(TableA.Members, TableB.Members) As Members
, TableB.Vacation
From TableA
Full Join TableB
On TableA.Members = TableB.Members
If there is nothing in common, then you could get the results you want using
a
Union like so:
Select A.Company, A.Sales, A.Members, Null As Vacation
From TableA As A
Union
Select B.Company, Null, B.Members, B.Vacation
From TableB As B
Using Union will give you a distinct list across the two tables. Using Union
All
will give you all items from both tables even if a duplicate is produced.
Thomas
"William" <da@.northernit.net> wrote in message
news:ikoke.16188$tM3.4933@.twister.nyroc.rr.com...
> What type of Query should I use to combine two sets of data into the same
> recordset. Note that none of the companies in TableA are the same as the
> companies in TableB (distinct sets of data).
> TableA
> Company, Sales, Members
> Table B
> Company, Members, Vacation
> Query Should Produce
> Company, Sales, Members Vacations
>

Tuesday, March 20, 2012

queries

my function needs to execute 3 queries. is it faster to execute 3 queries
seperately or make a combine query?
update query
execute
update query
execute
insert query
execute
OR
update query;update query;insert query
execute>> is it faster to execute 3 queries seperately or make a combine query?
There is no such heuristic; it depends on what each of the DML statements
do, the indexes involved, the magnitude of the underlying datasets etc. Test
it out both ways are find it out yourself.
Anith|||First of all, your pseudo-code has NO queries at all! UPDATE and
INSERT INTO are statements; they change data. Queries do not change
data. Next, what the heck is EXECUTE? that calls a procedure in
T_SQL.
Finally, who knows? You gave no code to look at, hint about any
relationship that need to be maintained, etc. Can uyou explain what you
meant?