SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 28th, 2004, 04:56 AM
nikeman_1479 nikeman_1479 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 13 nikeman_1479 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 24 m 27 sec
Reputation Power: 0
Unhappy Help needed please

I'm developing a database in sql and i'm faced with this problem in a procedure:
Server: Msg 156, Level 15, State 1, Procedure prospect, Line 35
Incorrect syntax near the keyword 'order'.
the line is:
declare reg_cs cursor local dynamic scroll for (select cod_imovel,area,preco from imoveis where (cod_reg=@tmpreg and cod_acab=@tmpacab and cod_estado=@tmpest and cod_tipo=@tmptipo and cod_tipologia=@tmptipolo and cod_local=@tmplocal and area=@area and preco!=@preco) order by preco asc))
The preco variable is of typ money in my database, and the @preco variable is of type float, i use the same like before to obtain is there is a line in the database with the parameter that i want and it doesn't have no error, if i take the order by state theres no error.
If anybody could help i thanks in advance. I can't finish my work because of this procedure, i'm stuck
If it's of any help this the full procedure:
create procedure prospect @preco float,@area float,@local varchar(30),@reg varchar(30),@tipolo varchar(20),@acab varchar(20),@estado varchar(20),@tipo varchar(30)
as
declare @tmplocal as int
declare @tmpreg as int
declare @tmptipolo as int
declare @tmpacab as int
declare @tmpest as int
declare @tmptipo as int
declare @codtmp as int
declare @precotmp as money
declare @areatmp as float
if ((select cod_local from localizacao where localizacao = @local)>0 and (select cod_regiao from regiao where nome = @reg)>0 and (select cod_tipologia from tipologia where tipologia = @tipolo)>0 and (select cod_acabamentos from acabamentos where acabamentos = @acab)>0 and (select cod_estado from estado where estado=@estado)>0 and (select cod_tipo from tipos where tipo=@tipo)>0)begin
select @tmplocal=cod_local from localizacao where localizacao = @local
select @tmpreg=cod_regiao from regiao where nome = @reg
select @tmptipolo=cod_tipologia from tipologia where tipologia = @tipolo
select @tmpacab=cod_acabamentos from acabamentos where acabamentos = @acab
select @tmpest=cod_estado from estado where estado=@estado
select @tmptipo=cod_tipo from tipo where tipo=@tipo
--Para todos os parametros
create table #prospects(cod_imov int,area float, preco money)
if exists (select cod_imovel from imoveis where cod_reg=@tmpreg and cod_acab=@tmpacab and cod_estado=@tmpest and cod_tipo=@tmptipo and cod_tipologia=@tmptipolo and cod_local=@tmplocal and preco=@preco and area=@area) begin
declare reg_cs cursor local dynamic scroll for (select cod_imovel,area,preco from imoveis where cod_reg=@tmpreg and cod_acab=@tmpacab and cod_estado=@tmpest and cod_tipo=@tmptipo and cod_tipologia=@tmptipolo and cod_local=@tmplocal and preco=@preco and area=@area)
open reg_cs
fetch next from reg_cs into @codtmp,@areatmp,@precotmp
while @@fetch_status = 0 begin
insert into #prospects(cod_imov,area,preco) values (@codtmp,@areatmp,@precotmp)
fetch next from reg_cs into @codtmp,@areatmp,@precotmp
end
close reg_cs
deallocate reg_cs
end

--Para todos menos o preço
if exists (select cod_imovel from imoveis where cod_reg=@tmpreg and cod_acab=@tmpacab and cod_estado=@tmpest and cod_tipo=@tmptipo and cod_tipologia=@tmptipolo and cod_local=@tmplocal and area=@area and preco!=@preco ) begin
declare reg_cs cursor local dynamic scroll for (select cod_imovel,area,preco from imoveis where cod_reg=@tmpreg and cod_acab=@tmpacab and cod_estado=@tmpest and cod_tipo=@tmptipo and cod_tipologia=@tmptipolo and cod_local=@tmplocal and area=@area and preco != @preco order by preco asc)
open reg_cs
fetch next from reg_cs into @codtmp,@areatmp,@precotmp
while @@fetch_status = 0 begin
insert into #prospects(cod_imov,area,preco) values (@codtmp,@areatmp,@precotmp)
fetch next from reg_cs into @codtmp,@areatmp,@precotmp
end
close reg_cs
deallocate reg_cs
end
--para todos menos o preco e a area
if exists (select cod_imovel from imoveis where cod_reg=@tmpreg and cod_acab=@tmpacab and cod_estado=@tmpest and cod_tipo=@tmptipo and cod_tipologia=@tmptipolo and cod_local=@tmplocal and area<>@area and preco!=@preco ) begin
declare reg_cs cursor local dynamic scroll for (select cod_imovel,area,preco from imoveis where cod_reg=@tmpreg and cod_acab=@tmpacab and cod_estado=@tmpest and cod_tipo=@tmptipo and cod_tipologia=@tmptipolo and cod_local=@tmplocal and area!=@area and preco != @preco order by (preco/area) asc)
open reg_cs
fetch next from reg_cs into @codtmp,@areatmp,@precotmp
while @@fetch_status = 0 begin
insert into #prospects(cod_imov,area,preco) values(@codtmp,@areatmp,@precotmp)
fetch next from reg_cs into @codtmp,@areatmp,@precotmp
end
close reg_cs
deallocate reg_cs
end
--para todos menos o preco, area e localização
if exists (select cod_imovel from imoveis where cod_reg=@tmpreg and cod_acab=@tmpacab and cod_estado=@tmpest and cod_tipo=@tmptipo and cod_tipologia=@tmptipolo and cod_local!=@tmplocal and area!=@area and preco!=@preco ) begin
declare reg_cs cursor local dynamic scroll for (select cod_imovel,area,preco from imoveis where cod_reg=@tmpreg and cod_acab=@tmpacab and cod_estado=@tmpest and cod_tipo=@tmptipo and cod_tipologia=@tmptipolo and cod_local!=@tmplocal and area!=@area and preco != @preco order by cod_local desc,preco,area)
open reg_cs
fetch next from reg_cs into @codtmp,@area,@precotmp
while @@fetch_status = 0 begin
insert into #prospects(cod_imov,area,preco) values(@codtmp,@areatmp,@precotmp)
fetch next from reg_cs into @codtmp,@areatmp,@precotmp
end
close reg_cs
deallocate reg_cs
end
end
else
print 'Campos introduzidos não estam correctos'

Ruben Monteiro

Reply With Quote
  #2  
Old May 28th, 2004, 11:10 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
What happens to your results if you don't sort?


Try removing the asc (it is ascending by default)

S-

Reply With Quote
  #3  
Old May 28th, 2004, 11:23 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
This may be the error.
Code:
order by (preco/area)

I don't think you can order by a calculation unless that calculation has been declared previously...like this
Code:
SELECT preco/area As 'total'
FROM TableName
ORDER BY total

Reply With Quote
  #4  
Old May 28th, 2004, 04:11 PM
nikeman_1479 nikeman_1479 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 13 nikeman_1479 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 24 m 27 sec
Reputation Power: 0
Exclamation

The procedure gives an error on each order by. You can do the calculation on the order by i tried the select with values and it works just fine. I don't know why it gives the error on each of the order by, if you don't use the @preco varaible it works just perfect. I'm hang on this to finish my job

Reply With Quote
  #5  
Old May 28th, 2004, 05:49 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
Quote:
Originally Posted by sbaxter
What happens to your results if you don't sort?



S-


?????
S-

Reply With Quote
  #6  
Old May 28th, 2004, 06:02 PM
nikeman_1479 nikeman_1479 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 13 nikeman_1479 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 24 m 27 sec
Reputation Power: 0
it order by the preco column 'preco' means price of something.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Help needed please


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT