Wednesday, March 28, 2012

IF ELSE not compiling

I can't seem to figure out why this SP would not compile. Your assistance i
s
much appreciated.
CREATE PROCEDURE sp_getPubId
@.name varchar, @.pubCode varchar, @.pubId smallint Output
AS
DECLARE maxPubId smallint
if (exists
(select publication_id from publication where code =@.pubCode))
begin
@.maxPubId=(select publication_id from publication where code =@.pubCode)
@.pubId=@.maxPubId
end
else begin
@.maxPubId=select max(publication_id) from publication
insert into publication(publication_id, name, code, creation_date,
update_date, last_user_id, status, transmit_app, application_type,
flags)values(@.maxPubId, @.name, @.pubCode, getDate(), getDate(), 13, 1, 1, 1,0
)
@.pubId=@.maxPubId+1
end
return
--
bicHi
Just try it this way:
SET @.maxPubId=(select publication_id from publication where code =@.pubCode)
SET @.pubId=@.maxPubId
.
.
.
best Regards,
Chandra
http://chanduas.blogspot.com/
http://groups.msn.com/SQLResource/
---
"bic" wrote:

> I can't seem to figure out why this SP would not compile. Your assistance
is
> much appreciated.
> CREATE PROCEDURE sp_getPubId
> @.name varchar, @.pubCode varchar, @.pubId smallint Output
> AS
> DECLARE maxPubId smallint
> if (exists
> (select publication_id from publication where code =@.pubCode))
> begin
> @.maxPubId=(select publication_id from publication where code =@.pubCode)
> @.pubId=@.maxPubId
> end
> else begin
> @.maxPubId=select max(publication_id) from publication
> insert into publication(publication_id, name, code, creation_date,
> update_date, last_user_id, status, transmit_app, application_type,
> flags)values(@.maxPubId, @.name, @.pubCode, getDate(), getDate(), 13, 1, 1, 1
,0)
> @.pubId=@.maxPubId+1
> end
> return
> --
> bic|||Thanks so much. You've solved a problem which plagued me for better part of
today. Thanks again.
--
bic
"bic" wrote:

> I can't seem to figure out why this SP would not compile. Your assistance
is
> much appreciated.
> CREATE PROCEDURE sp_getPubId
> @.name varchar, @.pubCode varchar, @.pubId smallint Output
> AS
> DECLARE maxPubId smallint
> if (exists
> (select publication_id from publication where code =@.pubCode))
> begin
> @.maxPubId=(select publication_id from publication where code =@.pubCode)
> @.pubId=@.maxPubId
> end
> else begin
> @.maxPubId=select max(publication_id) from publication
> insert into publication(publication_id, name, code, creation_date,
> update_date, last_user_id, status, transmit_app, application_type,
> flags)values(@.maxPubId, @.name, @.pubCode, getDate(), getDate(), 13, 1, 1, 1
,0)
> @.pubId=@.maxPubId+1
> end
> return
> --
> bic

No comments:

Post a Comment