|
 |
access thread: IF EXISTS - ELSE Usage in Stored Query
Message #1 by "David Lund" <davidlund@h...> on Fri, 24 May 2002 19:22:16
|
|
Hello All,
I am trying to do something like what is in this stored procedure for SQL
Server, in Access via a stored query. Let me say up front that almost all
of my development has been against SQL2000 and not Access.
Here is the code: _____________________
CREATE PROCEDURE sp_NameFromLogin
(
@LoginName varchar(8)
)
AS
IF EXISTS(SELECT 'True' FROM Login WHERE LoginName = @LoginName)
BEGIN
--record exists, return it to ASP with name of person
SELECT Person.FName, Person.LName
FROM Login
JOIN Person
ON Login.PersonID = Person.PersonID
WHERE Login.LoginName = @LoginName
END
ELSE
BEGIN
--This means the record isn't there, give error msg
SELECT @LoginName ' is NOT RECOGNIZED'
END
_________________________________
Basically, I am passing in the Login ID from asp, connnecting via oledb,
and calling the stored query with:
con.Execute "exec sp_NameFromLogin " & request.form('loginName')
or I am trying to rather.
Thanks for any help.
davlun
Message #2 by "Amy Wyatt" <amyw@c...> on Thu, 30 May 2002 13:38:48
|
|
I would like to help but I am a little confused at what you are trying to
accomplish. I am at the opposite end of the spectrum from you. I do most
of my development in Acces and a little against SQL2000. Can you tell me
exactly what you are trying to accoplish on the Access end?
Are you just trying to return the Login Name from SQL or are you trying to
run a query in Access that is based on what the returned login name? Are
you trying to open a form or anything like that? Are you getting an error
or is it just not doing anything?
Let me know and I will try to help.
Amy
> Hello All,
> I am trying to do something like what is in this stored procedure for
SQL
S> erver, in Access via a stored query. Let me say up front that almost
all
o> f my development has been against SQL2000 and not Access.
> Here is the code: _____________________
C> REATE PROCEDURE sp_NameFromLogin
(>
> @LoginName varchar(8)
)>
A> S
I> F EXISTS(SELECT 'True' FROM Login WHERE LoginName = @LoginName)
B> EGIN
> --record exists, return it to ASP with name of person
> SELECT Person.FName, Person.LName
> FROM Login
> JOIN Person
> ON Login.PersonID = Person.PersonID
> WHERE Login.LoginName = @LoginName
E> ND
E> LSE
B> EGIN
> --This means the record isn't there, give error msg
> SELECT @LoginName ' is NOT RECOGNIZED'
E> ND
_> ________________________________
> Basically, I am passing in the Login ID from asp, connnecting via oledb,
a> nd calling the stored query with:
> con.Execute "exec sp_NameFromLogin " & request.form('loginName')
> or I am trying to rather.
> Thanks for any help.
d> avlun
|
|
 |