I need some help maybe somebody can help me with this. I'm tyring to run this query, however the out result is only one Record but if i run the select statement without declare I get a bunch, can someone see what i'm doing wrong please. Thanks in advanced.
LROD -
-
declare @quotedate datetime
-
declare @AccName varchar(80)
-
declare @AccRept varchar(80)
-
declare @ContractAMT varchar(20)
-
declare @QuotedRate varchar(20)
-
declare @Booked_YN varchar(4)
-
declare @Status varchar(50)
-
declare @Booked_DT datetime
-
-
-
select
-
@quotedate = QD.QuoteDate,
-
@AccName = ac2.contact_nm,
-
@AccRept = ac1.contact_nm,
-
@ContractAMT = OD1.AMOUNT_NR ,
-
@QuotedRate = CASE WHEN OD2.AMOUNT_NR <0 THEN (od1.amount_nr - (OD2.AMOUNT_NR *-1) ) END,
-
@Booked_YN = case when o.order_status_cd in (995,994) then 'N'
-
when o.order_status_cd in (997,996) then 'Y' end,
-
@Status = o.order_status_cd,
-
@Booked_DT = BD.BookedDate
-
-
from t_order o
-
left outer join (
-
SELECT ORDER_ID,SUM(AMOUNT_NR)AS 'AMOUNT_NR'
-
FROM t_detail
-
WHERE detail_type_cd <> 600
-
GROUP BY ORDER_ID
-
)OD1 ON O.ORDER_ID = OD1.ORDER_ID
-
-
left outer join (
-
select order_id,new_value_ds, min(updated_dt)'BookedDate'
-
from t_history
-
where field_nm = 'Status_CD'and new_value_ds = '500'
-
group by order_id,new_value_ds
-
)BD on o.order_id = BD.order_id
-
-
left outer join (
-
select min(updated_dt)'QuoteDate'
-
from t_history
-
)QD on o.order_id = QD.order_id
-
-
-
left outer join t_detail od2 on o.order_id = od2.order_id and od2.order_detail_type_cd =582
-
left outer join t_contact oc1 (nolock)on o.order_id = oc1.order_id and oc1.contact_role_type_cd=300
-
left outer join t_contact1 ac1 (nolock)on oc1.contact_id = ac1.contact_id
-
left outer join t_contact2 oc2 (nolock)on o.order_id = oc2.order_id and oc2.contact_role_type_cd=220
-
left outer join t_contact3 ac2 (nolock)on oc2.contact_id = ac2.contact_id
-
-
where
-
o.order_cd = 1111
-
-
and QD.QuoteDate >= '3/23/09'
-
and QD.QuoteDate <= '3/24/09'
-
order by o.order_id desc
-
-
-
-
select
-
@quotedate 'QuoteDate',
-
@AccName 'AccountName',
-
@AccRept 'AccountRept',
-
@ContractAMT 'Contract_AMT',
-
@QuotedRate 'Quoted Rated',
-
@Booked_YN 'Booked Y/N',
-
@Status 'order_status_cd',
-
@Booked_DT 'BookedDate'
-
-
6 2193 ck9663 2,878
Recognized Expert Specialist
Because your query will run and will store the value of the last record to your variable.
Read more info from here
-- CK
i'm a newbie at this CK, I really not sure what should i do, do you think i should use SET on my variables then...can you help me out? Thanks in advanced
ck9663 2,878
Recognized Expert Specialist
Of you need the process each record you might need to use CURSOR. Depends actually on what you're trying to do.
-- CK
Well here is the whole code. If i run this code it only gives me one record during the time range, however if i run the main sql query i get about 90 records and that's what i should get when i run the whole code, same quantity. -
-
declare @string varchar(500)
-
declare @quotedate datetime --varchar(100)
-
declare @AccName varchar(80)
-
declare @AccRept varchar(80)
-
declare @AMT varchar(20)
-
declare @QuotedRate varchar(20)
-
declare @Booked_YN varchar(4)
-
declare @Status varchar(50)
-
declare @Booked_DT datetime --varchar(100)
-
-
set @string = 'ds'
-
-
-----------------------------------------------START MAIN QUERY--------------------------------------
-
select
-
-
@string = o.ds,
-
@quotedate = QD.QuoteDate,
-
@AccName = ac2.contact_nm,
-
@AccRept = ac1.contact_nm,
-
@AMT = OD1.AMOUNT_NR,
-
@QuotedRate = CASE WHEN OD2.AMOUNT_NR <0 THEN (od1.amount_nr - (OD2.AMOUNT_NR *-1) ) END,
-
@Booked_YN = case when o.status_cd in (100,200,300,400,500)then 'N'
-
when o.status_cd in (110,210,310,410,510,610,710,810,910,920) then 'Y' end ,
-
@Status = o.status_cd,
-
@Booked_DT = BD.BookedDate
-
-
from t_order o
-
left outer join (
-
SELECT ID,SUM(AMOUNT_NR)AS 'AMOUNT_NR'
-
FROM t_detail
-
WHERE detail_type_cd <> 980
-
GROUP BY ID
-
)OD1 ON O.ID = OD1.ID
-
-
left outer join (
-
select id,new_value_ds, min(updated_dt)'BookedDate'
-
from t_history
-
where field_nm = 'Status_CD'and value_ds = '810'
-
group by id,_value_ds
-
)BD on o.id = BD.id
-
-
left outer join (
-
select id,min(updated_dt)'QuoteDate'
-
from t_history
-
group by id
-
)QD on o.id = QD.id
-
-
left outer join t_detail od2 on o.id = od2.id and od2.detail_type_cd =180
-
-
left outer join t_contact oc1 (nolock)on o.id = oc1.id and oc1.contact_type_cd=291
-
left outer join t_contact1 ac1 (nolock)on oc1.contact_id = ac1.contact_id
-
-
left outer join t_contact oc2 (nolock)on o.id = oc2.id and oc2.contact_type_cd=292
-
left outer join t_contact1 ac2 (nolock)on oc2.id = ac2.id
-
-
where
-
QD.QuoteDate >= '3/23/09' and
-
QD.QuoteDate <= '3/24/09'
-
-
-----------------------------------------------END MAIN QUERY--------------------------------------
-
-
-
declare @pos int
-
declare @piece varchar(500)
-
declare @variableCount int
-
declare @var1 varchar(25),@var2 varchar(25), @var3 varchar(25), @var4 varchar(25)
-
,@var5 varchar(25), @var6 varchar(25)
-
-
set @variableCount = 1
-
-
if right(rtrim(@string),1) <> '/'
-
set @string = @string + '/'
-
set @pos = patindex('%/%' , @string)
-
while @pos <> 0
-
begin
-
set @piece = left(@string, @pos - 1)
-
-
-
if @variableCount = 1
-
begin
-
set @var1=@piece
-
end
-
else if @variableCount = 2
-
begin
-
set @var2=@piece
-
end
-
else if @variableCount = 3
-
begin
-
set @var3=@piece
-
end
-
else if @variableCount = 4
-
begin
-
set @var4=@piece
-
end
-
else if @variableCount = 5
-
begin
-
set @var5=@piece
-
end
-
else if @variableCount = 6
-
begin
-
set @var6=@piece
-
end
-
-
set @string = stuff(@string, 1, @pos, '')
-
set @pos = patindex('%/%' , @string)
-
set @variableCount = @variableCount + 1
-
end
-
-
-
print @quotedate
-
print @AccName
-
print @AccRept
-
print @AMT
-
print @QuotedRate
-
print @Booked_YN
-
print @Status
-
print @Booked_DT
-
print @var1
-
print @var2
-
print @var3
-
print @var4
-
print @var5
-
print @var6
-
-
select
-
@quotedate 'QuoteDate'
-
,@AccName 'AccountName'
-
,@AccRept 'AccountRept'
-
,@AMT 'AMT'
-
,@QuotedRate 'QuotedRated'
-
,@Booked_YN 'Booked_YN'
-
,@Status 'order_status_cd'
-
,@Booked_DT 'BookedDate'
-
,@var1 'OrigZip'
-
,@var2 'OrigST'
-
,@var3 'OrigCity'
-
,@var4 'DestZip'
-
,@var5 'DestState'
-
,@var6 'DestCity'
-
-
ck9663 2,878
Recognized Expert Specialist
I'm not sure why you need to print them or display it. Looks like CURSOR is your option. If you need this to be displayed in your GUI side, you might just want to control the returned result as result set.
--- CK
Thank you CK, I'll look into it and let you know what happened.
LROD
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Roy Adams |
last post by:
Hi posting again because no answer to previous..
tring to loop through a recordset and update a record, thing is it
only updates the first record in the table rather than searching
through the...
|
by: screenwriter776 |
last post by:
Hi, folks -
I have a control on a form that needs to store a single user-entered
(currency) amount, and store that amount for the next time another
user opens the form and views/updates it.
...
|
by: Mary Litten |
last post by:
Hi - (This is my very first post)
I have gotten to this point of registering to post because I have been
spinning my wheels so long, I believe I am all caught up in the weeds.
(and mud)
I have...
|
by: Vic |
last post by:
Dear All,
I have a database of laboratory records in Access 2000. There is one
form which acts as an interface to input experimetal data. This form
incorporates information from several tables....
|
by: Sami |
last post by:
I hope someone will tell me how to do this without having to do any VB
as I know nothing in that area. I am a rank beginner in using Access.
I have created a database consisting of student...
| |
by: Brett |
last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a
record in table2, then the not null fields in table1 that correspond to
the records in table1 needs to be updated to match the...
|
by: lorirobn |
last post by:
Hi,
I have a report that has a query as its record source.
The query picks up records from a table that meet certain criterion.
The report then counts how many records there are for each key...
|
by: =?Utf-8?B?UHJhdmlu?= |
last post by:
We are using .net Framework 1.1
We are having one page on which we are using this Grid component.
From this page we open a popup for adding new record as well as for editing
an existing record...
|
by: =?Utf-8?B?UiBSZXllcw==?= |
last post by:
Hi,
I'm having an issue in my C#.NET desktop application where two or more
people viewing/editing the same record (from SQL Server) keep overwriting
each others changes.
Is there a setting in...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |