| Author |
Topic |
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-09-10 : 10:26:15
|
| select max(an.executiontime), max(blu.executiontime, max(cp.executiontime, max(gl.executiontime, max(gw.executiontime, max(mor.executiontime, max(rlinv.executiontime, max(rlpr.executiontime, max(win.executiontime)from autonationcarinventory as an, bluenile_new as blu, carnivalpricing as cp, gaylordhotel as gl, greatwolf as gw,morganshotel as mor, royalinventory as rlinv, royalpricing as rlpr, winnebago as winMsg 156, Level 15, State 1, Line 4Incorrect syntax near the keyword 'from'.It's so simple, whats wrong with it? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-10 : 10:42:55
|
This is your query, just reformatted.See anything strange with it, besides the use of non-ansi style join?select max(an.executiontime), max(blu.executiontime, max(cp.executiontime, max(gl.executiontime, max(gw.executiontime, max(mor.executiontime, max(rlinv.executiontime, max(rlpr.executiontime, max(win.executiontime)from autonationcarinventory as an, bluenile_new as blu, carnivalpricing as cp, gaylordhotel as gl, greatwolf as gw, morganshotel as mor, royalinventory as rlinv, royalpricing as rlpr, winnebago as win E 12°55'05.63"N 56°04'39.26" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-10 : 10:44:08
|
That query will be a long running query...And the reads the query demands will make your spindles cry.Who designed this query? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-10 : 10:47:56
|
Try this one instead.Please run both queries and post back how long time each and one of them took.SELECT (SELECT MAX(executiontime) FROM autonationcarinventory), (SELECT MAX(executiontime) FROM bluenile_new), (SELECT MAX(executiontime) FROM carnivalpricing), (SELECT MAX(executiontime) FROM gaylordhotel), (SELECT MAX(executiontime) FROM greatwolf), (SELECT MAX(executiontime) FROM morganshotel), (SELECT MAX(executiontime) FROM royalinventory), (SELECT MAX(executiontime) FROM royalpricing), (SELECT MAX(executiontime) FROM winnebago) E 12°55'05.63"N 56°04'39.26" |
 |
|
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-09-16 : 11:37:14
|
| Your query worked great Peso!I'm trying to make SQL send me an email with the result of the query every 2 days. Is this possible using SQL Server Agent?I'm browsing through all the options and it doesn't seem to be there... ? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-16 : 11:53:33
|
| create a sql job to call xp_sendmail extended stored procedure which will sent the results of query as a mail. |
 |
|
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-09-26 : 11:27:44
|
trying to do something like this nowselect (select executiontime carn, count(executiontime) carncountfrom carnivalcleangroup by executiontime), (select executiontime carnraw, count(executiontime) carncounteufrom carnivalpricinggroup by executiontime)with a bunch of tables, but its giving me Msg 116, Level 16, State 1, Line 1Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.Msg 116, Level 16, State 1, Line 1Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. I dont understand, isn't it basically the same thing as Peso's query? His works but my new one doesn't |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 11:33:42
|
You can't return two values from a subquery. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-09-26 : 11:36:26
|
| Is there another way to do this?I'm trying to build a query that will show columns from different tables, but these columns will have a bunch of entries |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 11:36:46
|
How would you like to present the four values?One line as carn | carncount | carnraw | carncounteu1 | 15 | 2 | 24 or two lines astitle | countcarn | 15carnraw | 24 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-09-26 : 11:39:03
|
| these columns need to be placed side by side though, not joined into one column |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 11:40:56
|
Can you give an example? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-09-26 : 11:41:27
|
| I'm trying to make something that looks like thiscarn | carncount | carnraw | carnrawcount9/14 | 345 | 9/14 | 1239/13 | 456 | 9/13 | 3219/12 | 345 | 9/12 | 545from different tablen, where executiontime, is a column of date listings carn and carncount is from a table andcarnraw and carnrawcount is from another table |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 11:52:34
|
quote: Originally posted by sqlchiq trying to do something like this nowselect (select executiontime carn, count(executiontime) carncountfrom carnivalcleangroup by executiontime), (select executiontime carnraw, count(executiontime) carncounteufrom carnivalpricinggroup by executiontime)with a bunch of tables, but its giving me Msg 116, Level 16, State 1, Line 1Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.Msg 116, Level 16, State 1, Line 1Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. I dont understand, isn't it basically the same thing as Peso's query? His works but my new one doesn't
is this what you're looking at?select m.carn,m.carncount,tmp.carncounteufrom(select executiontime as carn, count(executiontime) as carncountfrom carnivalcleangroup by executiontime)minner join (select executiontime as carnraw, count(executiontime) as carncounteufrom carnivalpricinggroup by executiontime)tmpon tmp.carnraw=m.carn |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 11:52:39
|
[code]SELECT t1.carn, t1.carncount, t2.carnraw, t2.carncounteuFROM ( select executiontime as carn, count(executiontime) AS carncount from carnivalclean group by executiontime ) AS t1FULL JOIN ( select executiontime as carnraw, count(executiontime) as carncounteu from carnivalpricing group by executiontime ) AS t2 ON t2.carnraw = t1.carnORDER BY COALESCE(t1.carn, t2.carnraw) DESC[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
sqlchiq
Posting Yak Master
133 Posts |
Posted - 2008-09-26 : 11:59:04
|
quote: Originally posted by Peso
SELECT t1.carn, t1.carncount, t2.carnraw, t2.carncounteuFROM ( select executiontime as carn, count(executiontime) AS carncount from carnivalclean group by executiontime ) AS t1FULL JOIN ( select executiontime as carnraw, count(executiontime) as carncounteu from carnivalpricing group by executiontime ) AS t2 ON t2.carnraw = t1.carnORDER BY COALESCE(t1.carn, t2.carnraw) DESC E 12°55'05.63"N 56°04'39.26"
Is there anyway to get ride of those nulls?its goingnull null 9/13 321 null null 9/12 323null null 9/11 5469/13 654 null null9/12 465 null null9/11 321 null nullright nowAlso, I can add as many columns as I want right? I need to add about 5 more tables to this query |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 12:00:57
|
quote: Originally posted by sqlchiq
quote: Originally posted by Peso
SELECT t1.carn, t1.carncount, t2.carnraw, t2.carncounteuFROM ( select executiontime as carn, count(executiontime) AS carncount from carnivalclean group by executiontime ) AS t1FULL JOIN ( select executiontime as carnraw, count(executiontime) as carncounteu from carnivalpricing group by executiontime ) AS t2 ON t2.carnraw = t1.carnORDER BY COALESCE(t1.carn, t2.carnraw) DESC E 12°55'05.63"N 56°04'39.26"
Is there anyway to get ride of those nulls?its goingnull null 9/13 321 null null 9/12 323null null 9/11 5469/13 654 null null9/12 465 null null9/11 321 null nullright nowAlso, I can add as many columns as I want right? I need to add about 5 more tables to this query
you dont want nulls means you need inner join. then use the solution i provided. use inner join instead of full join. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 12:01:54
|
I find it quite impossible to get that resultset from this querySELECT t1.carn, t1.carncount, t2.carnraw, t2.carncounteuFROM ( select executiontime as carn, count(executiontime) AS carncount from carnivalclean group by executiontime ) AS t1FULL JOIN ( select executiontime as carnraw, count(executiontime) as carncounteu from carnivalpricing group by executiontime ) AS t2 ON t2.carnraw = t1.carnORDER BY COALESCE(t1.carn, t2.carnraw) DESC Because if carn and carnraw match, they should align. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 12:05:28
|
quote: Originally posted by visakh16 you dont want nulls means you need inner join. then use the solution i provided. use inner join instead of full join.
Visakh and sqlchig, look at this example of how NULL in the joins are handled...DECLARE @tableA TABLE ( ID INT, s INT )INSERT @tableASELECT 1, 1000 UNION ALLSELECT 2, 2000DECLARE @tableB TABLE ( ID INT, t INT )INSERT @tableBSELECT 2, 20 UNION ALLSELECT 3, 30-- Visakh16SELECT a.ID, a.s, b.ID, b.tFROM @tableA AS aINNER JOIN @tableB AS b ON b.ID = a.IDORDER BY a.ID DESC--PesoSELECT a.ID, a.s, b.ID, b.tFROM @tableA AS aFULL JOIN @tableB AS b ON b.ID = a.IDORDER BY COALESCE(a.ID, b.ID) DESC See the difference?Do you also see what happens when ID matches from both tables? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 12:39:23
|
quote: Originally posted by Peso
quote: Originally posted by visakh16 you dont want nulls means you need inner join. then use the solution i provided. use inner join instead of full join.
Visakh and sqlchig, look at this example of how NULL in the joins are handled...DECLARE @tableA TABLE ( ID INT, s INT )INSERT @tableASELECT 1, 1000 UNION ALLSELECT 2, 2000DECLARE @tableB TABLE ( ID INT, t INT )INSERT @tableBSELECT 2, 20 UNION ALLSELECT 3, 30-- Visakh16SELECT a.ID, a.s, b.ID, b.tFROM @tableA AS aINNER JOIN @tableB AS b ON b.ID = a.IDORDER BY a.ID DESC--PesoSELECT a.ID, a.s, b.ID, b.tFROM @tableA AS aFULL JOIN @tableB AS b ON b.ID = a.IDORDER BY COALESCE(a.ID, b.ID) DESC See the difference?Do you also see what happens when ID matches from both tables? E 12°55'05.63"N 56°04'39.26"
i didnt check the result posted. i thought OP needed only matched values. thats why i suggested use of INNER JOIN. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 14:53:37
|
The question still remains why OP got an erraneous resultset back. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
Next Page
|