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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Only one expression can be specified in the select
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ahmed_source
Starting Member

1 Posts

Posted - 06/16/2013 :  15:23:44  Show Profile  Reply with Quote
Hello all,

i think mt problem between ######
please help me


quote:


USE sum_stock_2013                       
begin
select itm_id
      ,itm_code
      ,itm_name
      ,price
      ,min_price
      ,open_balance
      ,end_open_balance
      ,value_cost
      ,doc_date
      ,suppliers
      ,reservation_qty
      ,order_qty
      ,sup_cat
      ,act_no
      ,act_name
      ,sanad
      ,type_namee
      ,type_no
      --,trn_date
      ,qty_out
      ,qty_in
      ,raseed
      ,storeno
from  (
      select
       distinct(i.itmid)     itm_id 
      ,i.code       itm_code       
      ,i.arbname    itm_name
      ,i.SelPrc1      price
      ,i.SelPrc1      min_price
      ,(select sum(itmo.StartBal) from itmonhand itmo where itmo.itmid= i.itmid)open_balance
      ,''end_open_balance
      ,ic.ItmCstPrc00 value_cost
      ,''doc_date
      ,''suppliers
      ,''reservation_qty
      ,''order_qty
      ,''sup_cat
      ,''act_no
      ,''act_name
      ,''sanad
      ,''type_namee
      ,''type_no
      --,trn_date
      ,''qty_out
      ,''qty_in
      ,''raseed
      ,''storeno
      
      from items as i
      left join itmonhand as itmo on (i.itmid = itmo.itmid)
      left join itmcost   as ic   on (i.itmid = ic.itmid)
union all

select td.itmid  itm_id
      ,''itm_code
      ,''itm_name
      ,''price
      ,''min_price
      ,''open_balance
      ,''end_open_balance
      ,''value_cost
      ,th.invdate doc_date
      ,''suppliers
      ,''reservation_qty
      ,''order_qty
      ,''sup_cat
      ,th.AcctID act_no
      ,th.InvCustName act_name
      ,th.InvNo sanad
      ,tt.arbname type_namee
      ,th.TrnID type_no
      --,trn_date
      ,case when td.invqty *-1 < 0 then 0 
       else td.invqty *-1
       end qty_out   --td.invqty *-1--(select sum(invqty)*-1 from trndet where itmid = i.itmid)
      ,case when td.invqty *-1 < 0 then td.invqty 
       else 0
       end qty_in

--################################################ MY Problem here

      ,(
select
rec
--,itm_no
--,qty

,(select SUM(QTY)
from (
select 1 rec
,itmo.itmid itm_no
,sum(itmo.StartBal) qty

from  itmonhand itmo
where itmid =33516
group by itmo.itmid
union 
select row_number() over (order by td.itmid) +1  rec
,td.itmid itm_no
,td.invqty qty

from  trndet td
where td.itmid =33516
)A

where REC<=MOV.REC --
)qty

from ( 
select         1 rec
,itmo.itmid itm_no
,sum(itmo.StartBal) qty

from  itmonhand itmo
where itmid =33516
group by itmo.itmid
union
select row_number() over (order by td.itmid)  +1 rec
,td.itmid itm_no
,td.invqty qty

from  trndet td
where td.itmid =33516)mov
 



) raseed


 --################# ##############################

      ,''storeno
      from trnhead th
           join trndet  td on (th.headid = td.headid)
      left join items   i  on (i.itmid   = td.itmid)
           join trntype tt on (tt.id     = th.trnid)
           
           
           

           
           
)as kk








where   itm_id in(select itmid from items where code = '2003012101002')
end;
--and     qty_out < 0
/*
where doc_date between convert(datetime,'01-01-2013',103)
               and     convert(datetime,'30-06-2013',103)
*/





Thank's

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 06/17/2013 :  01:08:34  Show Profile  Reply with Quote
rather than posting the query post some sample data and explain what you're trying to do giving expected output. That would be easier for us to understand your requirement rather than going through the above code without any information on tables and any data whatsoever

------------------------------------------------------------------------------------------------------
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.05 seconds. Powered By: Snitz Forums 2000