Hi guys,
I've been programming for quite a while now and just jumped in to SQL and Stored Procedures due to a Uni project I have due in.
I have a table called
tblWebsiteMember and tblWebsiteMember has 2 Columns -
ID and
Name
CREATE PROCEDURE CreateWebsiteMember
@wbmName
AS
INSERT INTO tblWebsiteMember (wbmName)
VALUES (@wbmName)
CREATE PROCEDURE GetWebsiteMember
@wbmName
AS
SELECT Name
FROM tblWebsiteMembers
WHERE Name = @wbmName
To create a member I execute CreateWebsiteMember and give the website member a name, then to check if the website member was added successfully I execute GetWebsiteMember with the newly created members name, all works fine.
My project is web based and I would prefer using 1 query in place of 2. So I figured I needed a way to return data on the query as a kind of validation.
CREATE PROCEDURE CreateWebsiteMember
@wbmName
AS
INSERT INTO tblWebsiteMember (wbmName)
VALUES (@wbmName)
SELECT 'True' AS Response
FROM tblWebsiteMember
WHERE UserName = @wbmUN
How do I return False in this example?
CREATE PROCEDURE CreateWebsiteMember
@wbmName
AS
INSERT INTO tblWebsiteMember (wbmName)
VALUES (@wbmName)
IF @wbmName = (SELECT Name FROM tblWebsiteMember WHERE Name = @wbmName)
RETURN 'True'
else
RETURN 'False'
A bit of a mish mash of languages here but I hope it gets the point across.
I cannot understand any learning resources out there for SQL, they seem to be very scare and complex compared to programming tutorials, but if anyone knows of a simple, similar tutorial for this, please do point me there.