| Author |
Topic |
|
tiwas
Starting Member
37 Posts |
Posted - 2009-12-15 : 04:23:54
|
Hi all,I'm struggling with the concept of stored procedures, and was hoping I could get some help from you guys here.I have the following DB:USE [xxxWebserv]GO/****** Object: Table [dbo].[kundeservice_lopenummer] Script Date: 12/15/2009 10:20:23 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[kundeservice_lopenummer]( [Lopenummer] [bigint] IDENTITY(1,1) NOT NULL, [Operator] [bigint] NOT NULL, [Kundenummer] [int] NULL, [utfall] [nvarchar](50) NULL, [Tidspunkt] [datetime] NOT NULL) ON [PRIMARY] What I need to do is enter an Operator and Time, and return the Lopenummer (ID) back to the caller. I then need to insert the rest when the user has completed the wizard.I've tried several, FAILED, versions of my procedure, and this is my current (still failing) version:USE [viasatWebserv]GO/****** Object: StoredProcedure [dbo].[cd_insert_lopenummer] Script Date: 12/15/2009 09:26:22 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[cd_insert_lopenummer] @operator bigint, @tidspunkt datetime,@kundenummer int,@utfall nvarchar(50)AS INSERT INTO [xxxWebserv].[dbo].[kundeservice_lopenummer]DECLARE @lopenummer bigint; VALUES (@operator ,@kundenummer ,@utfall ,@tidspunkt) SELECT SCOPE_IDENTITY()return lopenummer; Anyone? |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-15 : 04:27:58
|
| Change the Insert as below INSERT INTO [xxxWebserv].[dbo].[kundeservice_lopenummer] VALUES (@operator ,@kundenummer ,@utfall ,@tidspunkt) SELECT SCOPE_IDENTITY() as lopenummerSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-12-15 : 04:29:36
|
hiTry this.../****** Object: StoredProcedure [dbo].[cd_insert_lopenummer] Script Date: 12/15/2009 09:26:22 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[cd_insert_lopenummer] @operator bigint, @tidspunkt datetime, @kundenummer int, @utfall nvarchar(50)ASBEGIN INSERT INTO [xxxWebserv].[dbo].[kundeservice_lopenummer] VALUES (@operator ,@kundenummer ,@utfall ,@tidspunkt) SELECT SCOPE_IDENTITY() as lopenummerEND -------------------------R... |
 |
|
|
tiwas
Starting Member
37 Posts |
Posted - 2009-12-15 : 04:32:11
|
| Thanks for quick replies! Will try at once :) |
 |
|
|
tiwas
Starting Member
37 Posts |
Posted - 2009-12-15 : 04:38:58
|
BTW: would it be possible to insert the current datetime upon executing the stored procedure like?USE [xxxWebserv]GODECLARE @return_value intEXEC @return_value = [dbo].[cd_insert_lopenummer] @operator = 1, @tidspunkt = SELECT GETDATE()SELECT 'Return Value' = @return_valueGO |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-15 : 04:47:27
|
| USE [xxxWebserv]GODECLARE @return_value intEXEC @return_value = [dbo].[cd_insert_lopenummer] @operator = 1, @tidspunkt = GETDATE()SELECT 'Return Value' = @return_valueMadhivananFailing to plan is Planning to fail |
 |
|
|
tiwas
Starting Member
37 Posts |
Posted - 2009-12-15 : 04:52:41
|
madhivanan,This is the output I get Msg 102, Level 15, State 1, Line 6Incorrect syntax near ')'. I already tried changing it to that... |
 |
|
|
tiwas
Starting Member
37 Posts |
Posted - 2009-12-15 : 04:56:15
|
BTW, I changed my table toUSE [xxxWebserv]GO/****** Object: Table [dbo].[kundeservice_lopenummer] Script Date: 12/15/2009 10:55:10 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[kundeservice_lopenummer]( [Lopenummer] [bigint] IDENTITY(1,1) NOT NULL, [Operator] [bigint] NOT NULL, [Kundenummer] [int] NULL, [utfall] [nvarchar](50) NULL, [Tidspunkt] [datetime] NOT NULL CONSTRAINT [DF_kundeservice_lopenummer_Tidspunkt] DEFAULT (getdate())) ON [PRIMARY] |
 |
|
|
tiwas
Starting Member
37 Posts |
Posted - 2009-12-15 : 05:05:01
|
| Never mind! Just realised I had to pass NULL to the values I'm not setting :)Thanks! |
 |
|
|
|