Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Problems by setting a cursor


Message #1 by christian.huber@s... on Wed, 16 Jan 2002 18:37:10
Eva,
actually you are right. But first I tried to create this code without these
calender... I know, this is actually a big mistake! I will try this out, I
think this makes everything easier...

Chris

Christian Huber
Siemens Procurement and Logistics Services, LLC
c2p Operations - click2procureSM

4900 Old Ironsides Drive, Bldg.1
Mailstop 100
Santa Clara, CA 95054, USA
Tel.:  (408) 764-9223	Fax:  (xxx) xxx-xxxx

E-mail: christian.huber@s...
Siemens e-Procurement Solution/Buy-Side Marketplace:
<http://www.click2procure.com>
Be part of Siemens Suppliers? Suppliers Registration:
<http://click4suppliers.siemens.com> 




-----Original Message-----
From: Zadoyen, Eva [mailto:EZadoyen@s...]
Sent: Wednesday, January 16, 2002 10:55 AM
To: sql language
Subject: [sql_language] RE: Problems by setting a cursor


Chris,
Do you need week numbers just for counting purpose or real week numbers,
like in
"select datepart(ww,getdate())" where you will get the exact number of the
week in the calendar year?
	Eva

-----Original Message-----
From: Huber, Christian [mailto:Christian.Huber@s...]
Sent: Wednesday, January 16, 2002 1:53 PM
To: sql language
Subject: [sql_language] RE: Problems by setting a cursor


Thanks, but the problem is, I haven't got such a field.... actually I only
need the cursor for this variable @week. For example I have this start date
(10/01/01), this end date (12/31/01) and now I have to create for every
seven days a new table. The cursor should run until the start date <= end
date and @week = @week + 1. You know what I mean, or trying to do?!?
Chris

Christian Huber
Siemens Procurement and Logistics Services, LLC
c2p Operations - click2procureSM

4900 Old Ironsides Drive, Bldg.1
Mailstop 100
Santa Clara, CA 95054, USA
Tel.:  (408) 764-9223	Fax:  (xxx) xxx-xxxx

E-mail: christian.huber@s...
Siemens e-Procurement Solution/Buy-Side Marketplace:
<http://www.click2procure.com>
Be part of Siemens Suppliers? Suppliers Registration:
<http://click4suppliers.siemens.com> 




-----Original Message-----
From: Zadoyen, Eva [mailto:EZadoyen@s...]
Sent: Wednesday, January 16, 2002 10:46 AM
To: sql language
Subject: [sql_language] RE: Problems by setting a cursor


You are opening the cursor with "Select *'
If you have more than one field in your "*" then  your statement
 "fetch next from cursortime into 	@week " had to have all variables
matching the fields you are selecting.
Put "Select WEEK_FIELD from eneti_report..." and you will eliminate the
error message.
Good luck,
	Eva 

-----Original Message-----
From: Huber, Christian [mailto:Christian.Huber@s...]
Sent: Wednesday, January 16, 2002 1:42 PM
To: sql language
Subject: [sql_language] RE: Problems by setting a cursor


This is the error message:
Server: Msg 16924, Level 16, State 1, Procedure eneti_1, Line 39
Cursorfetch: The number of variables declared in the INTO list must match
that of selected columns.

But actually I am interested to know, where I have to set this cursor, or if
I have to use more than one cursor. Sorry, I am totally confused now...

Christian Huber
Siemens Procurement and Logistics Services, LLC
c2p Operations - click2procureSM

4900 Old Ironsides Drive, Bldg.1
Mailstop 100
Santa Clara, CA 95054, USA
Tel.:  (408) 764-9223	Fax:  (xxx) xxx-xxxx

E-mail: christian.huber@s...
Siemens e-Procurement Solution/Buy-Side Marketplace:
<http://www.click2procure.com>
Be part of Siemens Suppliers? Suppliers Registration:
<http://click4suppliers.siemens.com> 




-----Original Message-----
From: Breidenbach, Beth [mailto:Beth.Breidenbach@g...]
Sent: Wednesday, January 16, 2002 10:36 AM
To: sql language
Subject: [sql_language] RE: Problems by setting a cursor


What error are you receiving?

-----Original Message-----
From: christian.huber@s...
[mailto:christian.huber@s...]
Sent: Wednesday, January 16, 2002 10:37 AM
To: sql language
Subject: [sql_language] Problems by setting a cursor


Hi,
maybe I am to stupid to set this cursor. I have a start date and an end 
date, I have to create for every week(7 days) a new table with the same 
name (week_ + @number). I trying to set my cursor for more than one day,

actually it is not to difficult, but I am working the first time with 
dynamic sql and maybe this is confusing me. Maybe one of you can tell me
a 
solution. Here is the code:

CREATE PROCEDURE [dbo].[eneti_1] 
@start_date_eneti datetime,
@end_date_eneti datetime
as
declare
	@Supplier_Name nvarchar(50),
	@Purchase_Order_Num nvarchar(70),
	@Total_Amount decimal(18,3),
	@PO_Received_Date datetime,
	@week nvarchar(4),
	@nv_tablename nvarchar(50),
	@nv_sqltxt nvarchar(1000),
	@nv_sqltxtdrop nvarchar(500),
	@nv_test nvarchar(1000),
	@dt_start_date datetime,
	@dt_end_date datetime	

declare
	cursortime cursor for

select * from eneti_report where po_received_date >= @start_date_eneti
and 
po_received_date<= dateadd(week, 1, @start_date_eneti)  --name, 
purchase_order_Num, total_amount, po_received_date ,from eneti_report
--as 
timeframe  --select po_received_date,po_received_date from eneti_report

select @dt_start_date = dateadd(week, 1, @start_date_eneti)
select @dt_end_date = dateadd(week, 1, @end_date_eneti)
select @week = 1
select @week = @week + 1

open cursortime
fetch next from cursortime into
	@week
while (@dt_end_date <= @end_date_eneti) and (@@fetch_status = 0)
begin
select @nv_tablename = 'eneti_weekly_' + @week
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].' +

@nv_tablename) and OBJECTPROPERTY(id, N'IsUserTable')= 1) 
begin
	select @nv_sqltxtdrop = 'drop table [dbo].[' + @nv_tablename +
']'-
-[@nv_tablename]
	exec (@nv_sqltxtdrop)
end
select @nv_sqltxt = 'create table ' + @nv_tablename + 
	'(
	Supplier_Name nvarchar(50),
	Purchase_Order_Num nvarchar(70),
	Total_Amount decimal(18,3), 
	PO_Received_Date datetime
	)'

exec (@nv_sqltxt)
fetch next from cursortime into
	@week
end
exec eneti_2 @nv_tablename, @start_date_eneti, @end_date_eneti
close cursortime
deallocate cursortime
GO

Thanks in advance, Chris
$subst('Email.Unsub').

$subst('Email.Unsub').

$subst('Email.Unsub').

$subst('Email.Unsub').

$subst('Email.Unsub').

$subst('Email.Unsub').

  Return to Index