Group:  Microsoft Access ยป microsoft.public.access.adp.sqlserver
Thread: IF/THEN/ELSE

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

IF/THEN/ELSE
Greg 20.09.2006 20:16:02
I'm working on my first SQL Server application using Access as the front-end.
As I do understand the most simple stored procedures and use defined
functions, I have some things I'm not quite sure how to handle. List below is
an example of what I need to do and my goal is to handle the IF/THEN clause
within a single Stored Procedure, as I think this would be best.

I have a table called, tblTableSub, which may or may not have a record in
it. This table will contain one record based on the "TableID" value. If a
current record does exist, then I need to update that record, ELSE, if no
record exists, I need to ADD a record. Can someone give me the basic syntax
to build the IF/THEN structure?

Re: IF/THEN/ELSE
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)> 20.09.2006 20:47:15
Something like:

if Exists (Select * From tblTableSub Where tblTableSub.TableID = [ at ]Value)
Begin
update tblTableSub Set ....
End
Else
Begin
insert tblTableSub ....
end

The Begin ... End statements are used to group multiple statements into a
single block and are not needed if you have only one statement to be
executed by the IF or the Else clause.

A properly written SP will also look for any error by testing the [ at ][ at ]error
and [ at ][ at ]rowcount values and might also use transactions and set the proper
isolation level but I don't think you need this level of complexity right
now.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF


"Greg" <AccessVBAnet[ at ]newsgroups.nospam> wrote in message
news:4A29E34A-30FD-4A2F-AD03-CC164E9B3190[ at ]microsoft.com...
[Quoted Text]
> I'm working on my first SQL Server application using Access as the
> front-end.
> As I do understand the most simple stored procedures and use defined
> functions, I have some things I'm not quite sure how to handle. List below
> is
> an example of what I need to do and my goal is to handle the IF/THEN
> clause
> within a single Stored Procedure, as I think this would be best.
>
> I have a table called, tblTableSub, which may or may not have a record in
> it. This table will contain one record based on the "TableID" value. If a
> current record does exist, then I need to update that record, ELSE, if no
> record exists, I need to ADD a record. Can someone give me the basic
> syntax
> to build the IF/THEN structure?
>


Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net