|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Anyone looking for a way to modernize legacy data or easily migrate to a more cost-effective database without sacrificing functionality will benefit from this seminar. View the Intro to Advantage Database Server now! |
|
#1
|
|||
|
|||
|
Procedure problem
Why does only the first INSERT statement work???
CREATE PROCEDURE insert_inventory @item_name varchar(20), @description varchar(100), @notes varchar(255), @amount varchar(8) AS DECLARE @item_id int DECLARE @transaction_date datetime IF (@item_name = '') SET @item_name = NULL IF (@description = '') SET @description = NULL IF (@notes = '') SET @notes = NULL IF (@amount = '') SET @amount = NULL SET @item_id = IDENT_CURRENT('inventory') SET @transaction_date = GETDATE() INSERT INTO inventory (item_name, item_description, notes) VALUES (@item_name, @description, @notes) INSERT INTO expenditure (item_id, transaction_date, amount) VALUES (@item_id, @transaction_date, CAST(@amount AS money)) Also, where I have IF(@blah = '') SET.... I use these to convert blank fields in VB6 to NULL values, is there any easier way??? ![]() |
|
#2
|
|||
|
|||
|
Code:
CREATE PROCEDURE insert_inventory
@item_name varchar(20),
@description varchar(100),
@notes varchar(255),
@amount varchar(8)
AS
SET NOCOUNT ON
DECLARE @item_id int
DECLARE @transaction_date datetime
IF (@item_name = '') SET @item_name = NULL
IF (@description = '') SET @description = NULL
IF (@notes = '') SET @notes = NULL
IF (@amount = '') SET @amount = NULL
SET @transaction_date = GETDATE()
INSERT INTO inventory (item_name, item_description, notes) VALUES (@item_name, @description, @notes)
SET @item_id = IDENT_CURRENT('inventory')
INSERT INTO expenditure (item_id, transaction_date, amount) VALUES (@item_id, @transaction_date, CAST(@amount AS money))
|
|
#3
|
|||
|
|||
|
Wow, it works, I had found the problem with the @item_id not being between the two insert statements, but never would have guessed that the problem was with the SET NOCOUNT ON
What does it actually do??? besides making my SP work Cheers!!! ![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Procedure problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|