Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Incorrect syntax near from

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 win


Msg 156, Level 15, State 1, Line 4
Incorrect 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"
Go to Top of Page

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"
Go to Top of Page

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"
Go to Top of Page

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... ?
Go to Top of Page

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.
Go to Top of Page

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-09-26 : 11:27:44
trying to do something like this now

select (select executiontime carn, count(executiontime) carncount
from carnivalclean
group by executiontime),
(select executiontime carnraw, count(executiontime) carncounteu
from carnivalpricing
group by executiontime)


with a bunch of tables, but its giving me

Msg 116, Level 16, State 1, Line 1
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Msg 116, Level 16, State 1, Line 1
Only 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
Go to Top of Page

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"
Go to Top of Page

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
Go to Top of Page

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 | carncounteu
1 | 15 | 2 | 24
or two lines as
title   | count
carn | 15
carnraw | 24



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

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
Go to Top of Page

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"
Go to Top of Page

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-09-26 : 11:41:27
I'm trying to make something that looks like this

carn | carncount | carnraw | carnrawcount
9/14 | 345 | 9/14 | 123
9/13 | 456 | 9/13 | 321
9/12 | 345 | 9/12 | 545



from different tablen, where executiontime, is a column of date listings

carn and carncount is from a table and
carnraw and carnrawcount is from another table
Go to Top of Page

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 now

select (select executiontime carn, count(executiontime) carncount
from carnivalclean
group by executiontime),
(select executiontime carnraw, count(executiontime) carncounteu
from carnivalpricing
group by executiontime)


with a bunch of tables, but its giving me

Msg 116, Level 16, State 1, Line 1
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Msg 116, Level 16, State 1, Line 1
Only 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.carncounteu
from
(select executiontime as carn, count(executiontime) as carncount
from carnivalclean
group by executiontime)m
inner join (select executiontime as carnraw, count(executiontime) as carncounteu
from carnivalpricing
group by executiontime)tmp
on tmp.carnraw=m.carn
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-26 : 11:52:39
[code]SELECT t1.carn,
t1.carncount,
t2.carnraw,
t2.carncounteu
FROM (
select executiontime as carn,
count(executiontime) AS carncount
from carnivalclean
group by executiontime
) AS t1
FULL JOIN (
select executiontime as carnraw,
count(executiontime) as carncounteu
from carnivalpricing
group by executiontime
) AS t2 ON t2.carnraw = t1.carn
ORDER BY COALESCE(t1.carn, t2.carnraw) DESC[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

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.carncounteu
FROM (
select executiontime as carn,
count(executiontime) AS carncount
from carnivalclean
group by executiontime
) AS t1
FULL JOIN (
select executiontime as carnraw,
count(executiontime) as carncounteu
from carnivalpricing
group by executiontime
) AS t2 ON t2.carnraw = t1.carn
ORDER 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 going


null null 9/13 321
null null 9/12 323
null null 9/11 546
9/13 654 null null
9/12 465 null null
9/11 321 null null

right now


Also, I can add as many columns as I want right? I need to add about 5 more tables to this query
Go to Top of Page

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.carncounteu
FROM (
select executiontime as carn,
count(executiontime) AS carncount
from carnivalclean
group by executiontime
) AS t1
FULL JOIN (
select executiontime as carnraw,
count(executiontime) as carncounteu
from carnivalpricing
group by executiontime
) AS t2 ON t2.carnraw = t1.carn
ORDER 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 going


null null 9/13 321
null null 9/12 323
null null 9/11 546
9/13 654 null null
9/12 465 null null
9/11 321 null null

right now


Also, 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.
Go to Top of Page

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 query
SELECT		t1.carn,
t1.carncount,
t2.carnraw,
t2.carncounteu
FROM (
select executiontime as carn,
count(executiontime) AS carncount
from carnivalclean
group by executiontime
) AS t1
FULL JOIN (
select executiontime as carnraw,
count(executiontime) as carncounteu
from carnivalpricing
group by executiontime
) AS t2 ON t2.carnraw = t1.carn
ORDER 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"
Go to Top of Page

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 @tableA
SELECT 1, 1000 UNION ALL
SELECT 2, 2000

DECLARE @tableB TABLE
(
ID INT,
t INT
)

INSERT @tableB
SELECT 2, 20 UNION ALL
SELECT 3, 30

-- Visakh16
SELECT a.ID,
a.s,
b.ID,
b.t
FROM @tableA AS a
INNER JOIN @tableB AS b ON b.ID = a.ID
ORDER BY a.ID DESC

--Peso
SELECT a.ID,
a.s,
b.ID,
b.t
FROM @tableA AS a
FULL JOIN @tableB AS b ON b.ID = a.ID
ORDER 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"
Go to Top of Page

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 @tableA
SELECT 1, 1000 UNION ALL
SELECT 2, 2000

DECLARE @tableB TABLE
(
ID INT,
t INT
)

INSERT @tableB
SELECT 2, 20 UNION ALL
SELECT 3, 30

-- Visakh16
SELECT a.ID,
a.s,
b.ID,
b.t
FROM @tableA AS a
INNER JOIN @tableB AS b ON b.ID = a.ID
ORDER BY a.ID DESC

--Peso
SELECT a.ID,
a.s,
b.ID,
b.t
FROM @tableA AS a
FULL JOIN @tableB AS b ON b.ID = a.ID
ORDER 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.
Go to Top of Page

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"
Go to Top of Page
    Next Page

- Advertisement -