| Line | |
|---|
| 1 |
|
|---|
| 2 | SET ANSI_NULLS ON
|
|---|
| 3 | GO
|
|---|
| 4 | SET QUOTED_IDENTIFIER ON
|
|---|
| 5 | GO
|
|---|
| 6 |
|
|---|
| 7 | -- =============================================
|
|---|
| 8 | -- Author: marek
|
|---|
| 9 | -- Create date: 22/07/2009
|
|---|
| 10 | -- Description: Dodaje lub uaktualnia rekord zmiany emisji w tabeli ZmianyEmisji
|
|---|
| 11 | -- =============================================
|
|---|
| 12 | ALTER PROCEDURE [dbo].[sp_AddUpdateIssueChange]
|
|---|
| 13 | -- Add the parameters for the stored procedure here
|
|---|
| 14 | @issueId DECIMAL(18,0),
|
|---|
| 15 | @currentIssueNumer INT,
|
|---|
| 16 | @newIssueNumber INT
|
|---|
| 17 | AS
|
|---|
| 18 | BEGIN
|
|---|
| 19 | -- SET NOCOUNT ON added to prevent extra result sets from
|
|---|
| 20 | -- interfering with SELECT statements.
|
|---|
| 21 | SET NOCOUNT ON;
|
|---|
| 22 |
|
|---|
| 23 | -- Insert statements for procedure here
|
|---|
| 24 | DECLARE @rows INT
|
|---|
| 25 |
|
|---|
| 26 | SELECT @rows = COUNT(Id) FROM zmianyEmisji WHERE idEmisji=@issueId AND YEAR(dataZmiany)=YEAR(GETDATE()) AND MONTH(dataZmiany)=MONTH(GETDATE())
|
|---|
| 27 |
|
|---|
| 28 | IF @rows>0
|
|---|
| 29 | BEGIN
|
|---|
| 30 | UPDATE zmianyEmisji
|
|---|
| 31 | SET nastNrWyd=@newIssueNumber, dataZmiany=GETDATE()
|
|---|
| 32 | WHERE idEmisji=@issueId AND YEAR(dataZmiany)=YEAR(GETDATE()) AND MONTH(dataZmiany)=MONTH(GETDATE())
|
|---|
| 33 |
|
|---|
| 34 | --sprawdz czy nowy numer emisji nie jest taki sam jak stary numer, jesli tak to usun zmiane emisji
|
|---|
| 35 | DECLARE @issueNumber INT
|
|---|
| 36 | SELECT @issueNumber=popNrWyd FROM zmianyEmisji WHERE idEmisji=@issueId AND YEAR(dataZmiany)=YEAR(GETDATE()) AND MONTH(dataZmiany)=MONTH(GETDATE())
|
|---|
| 37 | IF @issueNumber=@newIssueNumber
|
|---|
| 38 | DELETE FROM zmianyEmisji WHERE idEmisji=@issueId AND YEAR(dataZmiany)=YEAR(GETDATE()) AND MONTH(dataZmiany)=MONTH(GETDATE())
|
|---|
| 39 | END
|
|---|
| 40 | ELSE
|
|---|
| 41 | BEGIN
|
|---|
| 42 | INSERT INTO zmianyEmisji(idEmisji, popNrWyd, nastNrWyd, dataZmiany)
|
|---|
| 43 | VALUES(@issueId, @currentIssueNumer, @newIssueNumber, GETDATE())
|
|---|
| 44 | END
|
|---|
| 45 |
|
|---|
| 46 | END
|
|---|
| 47 | GO
|
|---|
| 48 |
|
|---|
| 49 | SET ANSI_NULLS OFF
|
|---|
| 50 | GO
|
|---|
| 51 | SET QUOTED_IDENTIFIER OFF
|
|---|
| 52 | GO
|
|---|
| 53 |
|
|---|
Notatka: Zobacz
TracBrowser
aby uzyskać więcej informacji.