473,847 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MySql From MS SQL - What's wrong with this stored procedure?

I just switched from MS SQL 2000/2005 to MySql.

What's wrong with this stored procedure:

DELIMITER $$

DROP PROCEDURE IF EXISTS `listing`.`Save User` $$
CREATE DEFINER=`root`@ `localhost` PROCEDURE `SaveUser`(Id INT, Username
VARCHAR(50), EmailAddress VARCHAR(255), Salutation VARCHAR(10),
FirstName VARCHAR(50), LastName VARCHAR(50), Password VARCHAR(50),
Status INT)
BEGIN

DECLARE EmailAddressExi sts BIT;
DECLARE UsernameExists BIT;
DECLARE ActionDate DATETIME;

SET EmailAddressExi sts = 0;
SET UsernameExists = 0;

SET EmailAddressExi sts = !ISNULL((SELECT 1 FROM user WHERE
user.EmailAddre ss = EmailAddress AND NOT user.Id = Id));
SET UsernameExists = !ISNULL((SELECT 1 FROM user WHERE user.Username =
Username AND NOT user.Id = Id));

IF EmailAddressExi sts = FALSE AND UsernameExists = FALSE THEN
SET ActionDate = NOW();
IF ID 0 THEN
UPDATE user SET user.Username = Username, user.EmailAddre ss =
EmailAddress, user.Password = Password, user.Salutation = Salutation,
user.FirstName = FirstName, user.LastName = LastName, user.Status =
Status, user.Modified = ActionDate WHERE user.Id = Id;
ELSE
INSERT INTO user (Username, EmailAddress, Password, Salutation,
FirstName, LastName, Created) VALUES (Username, EmailAddress, Password,
Salutation, FirstName, LastName, ActionDate);
SET Id = @@IDENTITY;
END IF;
END IF;

SELECT Id, ActionDate, EmailAddressExi sts, UsernameExists;

END $$

DELIMITER ;

Basically,
I want the procedure to return Id, ActionDate, EmailAddressExi sts,
UsernameExists as a result set.

EmailAdressExis ts needs to be set true or false.
In MS SQL, I could do SELECT @EmailAddressEx ists = 1 FROM User where
username = 'asdsa';

It looks like that doesn't work in MySql???

The MySql syntax doesn't look very standard. Who the hell came up with
LIMIT instead of TOP?

Dec 11 '06 #1
1 5017
ob***********@h otmail.com wrote:
I just switched from MS SQL 2000/2005 to MySql.

What's wrong with this stored procedure:

DELIMITER $$

DROP PROCEDURE IF EXISTS `listing`.`Save User` $$
CREATE DEFINER=`root`@ `localhost` PROCEDURE `SaveUser`(Id INT, Username
VARCHAR(50), EmailAddress VARCHAR(255), Salutation VARCHAR(10),
FirstName VARCHAR(50), LastName VARCHAR(50), Password VARCHAR(50),
Status INT)
BEGIN

DECLARE EmailAddressExi sts BIT;
DECLARE UsernameExists BIT;
DECLARE ActionDate DATETIME;

SET EmailAddressExi sts = 0;
SET UsernameExists = 0;

SET EmailAddressExi sts = !ISNULL((SELECT 1 FROM user WHERE
user.EmailAddre ss = EmailAddress AND NOT user.Id = Id));
SET UsernameExists = !ISNULL((SELECT 1 FROM user WHERE user.Username =
Username AND NOT user.Id = Id));

IF EmailAddressExi sts = FALSE AND UsernameExists = FALSE THEN
SET ActionDate = NOW();
IF ID 0 THEN
UPDATE user SET user.Username = Username, user.EmailAddre ss =
EmailAddress, user.Password = Password, user.Salutation = Salutation,
user.FirstName = FirstName, user.LastName = LastName, user.Status =
Status, user.Modified = ActionDate WHERE user.Id = Id;
ELSE
INSERT INTO user (Username, EmailAddress, Password, Salutation,
FirstName, LastName, Created) VALUES (Username, EmailAddress, Password,
Salutation, FirstName, LastName, ActionDate);
SET Id = @@IDENTITY;
END IF;
END IF;

SELECT Id, ActionDate, EmailAddressExi sts, UsernameExists;

END $$

DELIMITER ;

Basically,
I want the procedure to return Id, ActionDate, EmailAddressExi sts,
UsernameExists as a result set.

EmailAdressExis ts needs to be set true or false.
In MS SQL, I could do SELECT @EmailAddressEx ists = 1 FROM User where
username = 'asdsa';

It looks like that doesn't work in MySql???

The MySql syntax doesn't look very standard. Who the hell came up with
LIMIT instead of TOP?
What version of MySQL?
what error do you get when you execute it?
--
Michael Austin.
Database Consultant
Dec 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3279
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant section from the manual: 20.1.9.7 WHILE Statement
15
4660
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
0
19303
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a hell of a time with it... The following comes from phpinfo(): PHP Version: 5.1.2 mysql Client API version: 5.0.18 mysqli Client API version: 5.0.18
0
3587
by: moira.shrimpton | last post by:
Hi, Heres a little test sp, I can't get it to use the @H variable in the select , what am i doing wrong?, been messing for days now :( The row caount always comes back as 0 , but if I just change the line "SELECT count(*) INTO s from test where url=@'H';" to use url='tony' for example or any other value it works as expected.
2
6126
by: bshumsky06 | last post by:
Hi, I am trying to create stored procedures in MySQL. Does anyone have a suggestion on a good IDE to use. I have been working with the MySQL Query Browser but it generates errors very often and is shut down by Windows. When I make changes to my procedure, it doesn't seem to always change what is being executed. Furthermore, sometimes the procedure just disappears from my database. I am starting to think that the stored procedure...
1
1836
by: Ted | last post by:
In MS SQL I used the following to create a stored procedure. USE AdventureWorks; GO IF OBJECT_ID ( 'HumanResources.usp_My_Search', 'P' ) IS NOT NULL DROP PROCEDURE HumanResources.usp_My_Search; GO CREATE PROCEDURE HumanResources.usp_My_Search @searchstring varchar(40) AS
7
5847
by: eholz1 | last post by:
Hello PHP group, Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0 running on Linux (Redhat Fedora Core 6). All that works fine. I would like to be able to "call" a stored procedure from a PHP program, and run a stored procedure. I have yet to figure out the proper way to do this. My stored procedures work fine from the mysql command line using syntax: "call sp_min_record (101);"
1
14059
by: preejith | last post by:
Error Code : 1329, No data - zero rows fetched, selected, or processed. MYSQL I am getting the following error while running a stored procedure in mysql5.0 Error Code : 1329 No data - zero rows fetched, selected, or processed. I have an stored procedure SP1 which calls stored procedure SP2 and SP2 calls a function F1. I have run this script from .bat file.
1
9599
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of things (stored procedures, functions).. we have to manually edit. That time, we face some interesting challenges.. I failed to document all of them, but whatever I can share with u.. I will try.. :) ...
0
9730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10983
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10648
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7883
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4119
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3164
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.