SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pascal_jimi
Posting Yak Master

Azerbaijan
150 Posts

Posted - 11/09/2013 :  03:40:32  Show Profile  Visit pascal_jimi's Homepage  Reply with Quote
DECLARE @phone table(
phone int
);
insert into @phone
(phone)
values
(111)
insert into @phone
(phone)
values
(222)
insert into @phone
(phone)
values
(333)


DECLARE @servis table(
ph int ,
servis nvarchar(20)
);
insert into @servis
(ph,servis)
values
(111,'aciq')
insert into @servis
(ph,servis)
values
(111,'bagli')
insert into @servis
(ph,servis)
values
(111,'birbasa')
insert into @servis
(ph,servis)
values
(222,'birbasa')


DECLARE @qiymet table(
serv nvarchar(20),
qiym int
);

insert into @qiymet
(serv,qiym)
values
('birbasa',1)
insert into @qiymet
(serv,qiym)
values
('bagli',1)
insert into @qiymet
(serv,qiym)
values
('aciq',1)




select distinct(phone) as p,2 as deb from @phone as ph
left join
(
select nomre, sum(qiyme) as meb from(
select sw.ph as nomre,sw.servis ,qy.qiym as qiyme
from @servis as sw inner join @qiymet as qy on sw.servis=qy.serv
)g group by nomre
)o
on o.nomre=ph.p


but i getting error
error:
Invalid column name 'p'.

http://sql-az.tr.gg/

bitsmed
Constraint Violating Yak Guru

405 Posts

Posted - 11/09/2013 :  04:27:02  Show Profile  Reply with Quote
quote:
Originally posted by pascal_jimi
select nomre, sum(qiyme) as meb from(
select sw.ph as nomre,sw.servis ,qy.qiym as qiyme
from @servis as sw inner join @qiymet as qy on sw.servis=qy.serv
)g group by nomre
)o
on o.nomre=ph.p



select nomre
      ,sum(qiyme) as meb
  from (select sw.ph as nomre
              ,sum(qiyme) as meb
          from @servis as sw
               inner join @qiymet as qy
                       on sw.servis=qy.serv 
         group by nomre
       ) as o 
    on o.nomre=p.ph

Edited by - bitsmed on 11/09/2013 04:33:04
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 11/09/2013 :  10:36:28  Show Profile  Reply with Quote

select distinct 
phone as p,
2 as deb 
from @phone as ph
left join
(
select nomre, sum(qiyme) as meb 
from(
select sw.ph as nomre,sw.servis ,qy.qiym as qiyme
from @servis as sw inner join @qiymet as qy on sw.servis=qy.serv 
)g 
group by nomre
)o 
on o.nomre=ph.phone


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 11/11/2013 :  03:02:09  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
You cannot directly use alias name anywhere in the query except ORDER BY Clause

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pascal_jimi
Posting Yak Master

Azerbaijan
150 Posts

Posted - 11/12/2013 :  01:14:08  Show Profile  Visit pascal_jimi's Homepage  Reply with Quote
Thank you to all my friends

is special Thank you to all my friends

is special VISAKH MURUKESAN

http://sql-az.tr.gg/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 11/12/2013 :  01:42:05  Show Profile  Reply with Quote
quote:
Originally posted by pascal_jimi

Thank you to all my friends

is special Thank you to all my friends

is special VISAKH MURUKESAN

http://sql-az.tr.gg/


you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000