[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Exclude update of a field if parm is null

Brad Pears

3/15/2007 3:24:00 PM

I have a stored procedure that either inserts a row or updates a row. There
is a field in there that I would like to check for in the update section. If
the incoming parameter (pPDF) is null, I do not want to even issue an update
for that field. Can I cehck for this inline or do I have to write another
complete update statement again which would simply exclude that field if the
incoming parm is null?

Here is the stored procedure...

CREATE PROCEDURE dbo.sp_UpdateSteelPlateItem
(
@cSku as char(30),
@vcWidth1 as varchar(50),
@vcWidth2 as varchar(50),
@vcWidth3 as varchar(50),
@vcWidth4 as varchar(50),
@iSkewed as integer,
@vcThickness as varchar(50),
@iHoles as integer,
@iType as integer,
@iApplication as integer,
@iPurpose as integer,
@pPDF as image = null (this is the parm I want to check for null)
)

AS
--either update or insert into SteelPlates
if exists (select cSKU from tblSteelPlates where cSKU=@cSku)
begin
update tblSteelPlates set
cSku = @cSKU,
vcWidth1 = @vcWidth1,
vcWidth2 = @vcWidth2,
vcWidth3 = @vcWidth3,
vcWidth4 = @vcWidth4,
iSkewed = @iSkewed,
vcThickness = @vcThickness,
iHoles = @iHoles,
iType = @iType,
iApplication = @iApplication,
iPurpose = @iPurpose,
imgPlatePDF = @pPDF, (I want to exlude this if parm is null)
dtSteelPlateMod = getdate()
where cSku = @cSku
end
else
begin
INSERT INTO tblSteelPlates (cSku,vcWidth1, vcWidth2, vcWidth3,
vcWidth4,iSkewed, vcThickness,iHoles, iType, iApplication, iPurpose,
imgPlatePDF, dtSteelPlateInsert)
VALUES (@cSku, @vcWidth1, @vcWidth2, @vcWidth3, @vcWidth4, @iSkewed,
@vcThickness, @iHoles, @iType, @iApplication, @iPurpose, @pPDF, getdate())
end
GO




Thanks, Brad


3 Answers

Tom Cooper

3/15/2007 3:48:00 PM

0

Replace

iPurpose = @iPurpose,
imgPlatePDF = @pPDF, (I want to exlude this if parm is null)
dtSteelPlateMod = getdate()

with

iPurpose = @iPurpose,
imgPlatePDF = COALESCE (@pPDF, imgPlatePDF),
dtSteelPlateMod = getdate()

then if @pPDF is not null, imgPlatePDF will be updated to @pPDF, and if
@pPDF is null, imgPlatePDF will be updated to itself and the value will not
change.

Tom

"Brad Pears" <bradp@truenorthloghomes.com> wrote in message
news:usxMDWxZHHA.208@TK2MSFTNGP05.phx.gbl...
>I have a stored procedure that either inserts a row or updates a row.
>There is a field in there that I would like to check for in the update
>section. If the incoming parameter (pPDF) is null, I do not want to even
>issue an update for that field. Can I cehck for this inline or do I have to
>write another complete update statement again which would simply exclude
>that field if the incoming parm is null?
>
> Here is the stored procedure...
>
> CREATE PROCEDURE dbo.sp_UpdateSteelPlateItem
> (
> @cSku as char(30),
> @vcWidth1 as varchar(50),
> @vcWidth2 as varchar(50),
> @vcWidth3 as varchar(50),
> @vcWidth4 as varchar(50),
> @iSkewed as integer,
> @vcThickness as varchar(50),
> @iHoles as integer,
> @iType as integer,
> @iApplication as integer,
> @iPurpose as integer,
> @pPDF as image = null (this is the parm I want to check for null)
> )
>
> AS
> --either update or insert into SteelPlates
> if exists (select cSKU from tblSteelPlates where cSKU=@cSku)
> begin
> update tblSteelPlates set
> cSku = @cSKU,
> vcWidth1 = @vcWidth1,
> vcWidth2 = @vcWidth2,
> vcWidth3 = @vcWidth3,
> vcWidth4 = @vcWidth4,
> iSkewed = @iSkewed,
> vcThickness = @vcThickness,
> iHoles = @iHoles,
> iType = @iType,
> iApplication = @iApplication,
> iPurpose = @iPurpose,
> imgPlatePDF = @pPDF, (I want to exlude this if parm is null)
> dtSteelPlateMod = getdate()
> where cSku = @cSku
> end
> else
> begin
> INSERT INTO tblSteelPlates (cSku,vcWidth1, vcWidth2, vcWidth3,
> vcWidth4,iSkewed, vcThickness,iHoles, iType, iApplication, iPurpose,
> imgPlatePDF, dtSteelPlateInsert)
> VALUES (@cSku, @vcWidth1, @vcWidth2, @vcWidth3, @vcWidth4,
> @iSkewed, @vcThickness, @iHoles, @iType, @iApplication, @iPurpose, @pPDF,
> getdate())
> end
> GO
>
>
>
>
> Thanks, Brad
>
>


topaz

7/6/2014 5:58:00 AM

0

a most excellent post, I could not have said it better
Forcing devout Xian or Jewish owners to cover contraception when they believe it is against their faith would decrease the separation of church and state.





Thursday, July 3, 2014 2:40:50 PM UTC-4, shel...@thevillages.net wrote:
> On 7/3/2014 1:53 PM, Giborah wrote:
>
> > Very funny -- and dead accurate -- comment on HL and SCOTUS hypocrisy. Enjoy particularly #2 and 3.
>
> >
>
> > And guys, wait till the NEXT ruling comes down! You're not home free yet!
>
> >
>
> > http://bluenationreview.com/7-things-hobby-lobby-decision-will-make-hea...
>
> >
>
> > Giborah
>
> >
>
>
>
> Giborah, I just did a little research on line with "birth control pill
>
> prices" and quickly found this little snippet:
>
>
>
> "Tri-Sprintec is available for $9 for a monthly pack on Walmart�s
>
> generic drug program as well as on Target�s generic drug program."
>
>
>
> *NINE* stinking dollars a month!!!! That is less than ONE time at the
>
> movie theater! It is approximately one plain pizza! Where don't you
>
> piss away nine dollars over the course of a month? *We are talking
>
> about thirty cents a day*!!!! If they can't afford thirty cents a day,
>
> then there are groups (planned parenthood???) that can help them.
>
>
>
> No one is denying anyone access to birth control pills.
>
>
>
> BTW, when I was working for various different companies over the course
>
> of my working life, neither birth control pills nor ED medications were
>
> ever covered. They were always out of pocket expenses. Maybe times
>
> have changed in the last decade or so.
>
>
>
> Yes, I do see that you (and others) see this as an attitude change and a
>
> war on separation of church and state. However, there is an equally
>
> valid view that ruling the other way would have been a war on that
>
> separation. For once, please take two steps back and try to see that
>
> side of the argument. That being that ruling against Hobby Lobby (a
>
> privately held company, not publicly traded) would have been the state
>
> imposing rules that directly violated the owner's religious principles.
>
> Can you at least see *THAT* argument as also having merit -- even
>
> though you do not agree with it.
>
>
>
> --
>
> Shelly

Evertjan.

7/6/2014 2:22:00 PM

0

topazgalaxy <topazgalaxy@gmail.com> wrote on 06 jul 2014 in
soc.culture.jewish.moderated:

> Forcing devout Xian or Jewish owners to cover contraception when
> they believe it is against their faith would decrease the separation
> of church and state.

I would say forcing emloyees to be the subject of the "church" of the owner
would be contrary to the separation of church and state.

It is not the owner that covers contraception, but the insurance company.

"Against their faith" could so be extented to prevent paying certain taxes,
wellbeing, race segregation, etc. That way any any any law can, depending on
the "faith", be contrary to the separation of church and state.

Perhaps, just just just perhaps, it could be justified to be against their
faith to prevent effective contraception during de facto workinghours???

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)