Showing posts with label statements. Show all posts
Showing posts with label statements. Show all posts

Sunday, February 26, 2012

ELSEIF in Stored Procedures?

I have found some documentation regarding the use of IF...ELSE statements in stored procedures, but what about multiple condition statements? For example, say I need 3 unique fields in my table. If my application passes a value that is a duplicate in one of the columns, the stored proc will fail, but it is difficult to know which item caused the failure and therefore difficult for the user to get a meaningful error message in order to correct their input. I am thinking I could just make a conditional statement that applies a code to an OUTPUT parameter in order to clarify the error:

(pseudo code)

if @.field1 already exists then @.output = '1';terminate stored procedure

elseif @.field2 already exists then @.output = '2';terminate stored procedure

elseif @.field3 already exists then @.output = '3';terminate stored procedure

else finish the insert

(end pseudo code)

Are 'elseif' statements allowed in SQL Server? Am I going about this in the wrong way?

Jungalist wrote:

Are 'elseif' statements allowed in SQL Server?

Sort of. You can impletemt the logic as follows :

IF @.field1 already exists

BEGIN

SET @.OUTPUT = 1

END

ELSE

IF @.field2 already exists

BEGIN

SET @.OUTPUT=2

END

ELSE

IF @.field3 already exists

BEGIN

SET @.OUTPUT=3

END

check out books on line for "IF ELSE"

|||

Thank-you. I was searching for the wrong terms. I appreciate the help.

Friday, February 24, 2012

Efficient INSERT of rows- .NET

Hello- I have a C++ .NET application that rips through a raw file, generating
thousands of INSERT statements to insert into a SQL Server 2000 database
through the SQLConnection class in .NET. While this seems reasonably fast,
I'm wondering if it is the most efficient way of doing this. Would creating
a stored procedure on the SQL Server and then passing parameters to the SP
through the Command object be faster and more efficient? I've also
considered dumping the contents to a flat CSV file and using SQL Server DTS
to BULK INSERT the rows- but that is additional overhead in creating the CSV
file and then launching DTS etc. Any suggestions/comments would be
appreciated.
Thanks,
Jon
I replied to this in .programming. Please don't multipost. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Jonathan Porter" <JonathanPorter@.discussions.microsoft.com> wrote in message
news:D72A8997-D492-49A4-86DB-16C786771F3F@.microsoft.com...
> Hello- I have a C++ .NET application that rips through a raw file, generating
> thousands of INSERT statements to insert into a SQL Server 2000 database
> through the SQLConnection class in .NET. While this seems reasonably fast,
> I'm wondering if it is the most efficient way of doing this. Would creating
> a stored procedure on the SQL Server and then passing parameters to the SP
> through the Command object be faster and more efficient? I've also
> considered dumping the contents to a flat CSV file and using SQL Server DTS
> to BULK INSERT the rows- but that is additional overhead in creating the CSV
> file and then launching DTS etc. Any suggestions/comments would be
> appreciated.
> Thanks,
> Jon

Sunday, February 19, 2012

Efficient INSERT of rows- .NET

Hello- I have a C++ .NET application that rips through a raw file, generatin
g
thousands of INSERT statements to insert into a SQL Server 2000 database
through the SQLConnection class in .NET. While this seems reasonably fast,
I'm wondering if it is the most efficient way of doing this. Would creating
a stored procedure on the SQL Server and then passing parameters to the SP
through the Command object be faster and more efficient? I've also
considered dumping the contents to a flat CSV file and using SQL Server DTS
to BULK INSERT the rows- but that is additional overhead in creating the CSV
file and then launching DTS etc. Any suggestions/comments would be
appreciated.
Thanks,
JonI replied to this in .programming. Please don't multipost. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Jonathan Porter" <JonathanPorter@.discussions.microsoft.com> wrote in messag
e
news:D72A8997-D492-49A4-86DB-16C786771F3F@.microsoft.com...
> Hello- I have a C++ .NET application that rips through a raw file, generat
ing
> thousands of INSERT statements to insert into a SQL Server 2000 database
> through the SQLConnection class in .NET. While this seems reasonably fast
,
> I'm wondering if it is the most efficient way of doing this. Would creati
ng
> a stored procedure on the SQL Server and then passing parameters to the SP
> through the Command object be faster and more efficient? I've also
> considered dumping the contents to a flat CSV file and using SQL Server D
TS
> to BULK INSERT the rows- but that is additional overhead in creating the C
SV
> file and then launching DTS etc. Any suggestions/comments would be
> appreciated.
> Thanks,
> Jon

Efficient INSERT of rows- .NET

Hello- I have a C++ .NET application that rips through a raw file, generating
thousands of INSERT statements to insert into a SQL Server 2000 database
through the SQLConnection class in .NET. While this seems reasonably fast,
I'm wondering if it is the most efficient way of doing this. Would creating
a stored procedure on the SQL Server and then passing parameters to the SP
through the Command object be faster and more efficient? I've also
considered dumping the contents to a flat CSV file and using SQL Server DTS
to BULK INSERT the rows- but that is additional overhead in creating the CSV
file and then launching DTS etc. Any suggestions/comments would be
appreciated.
Thanks,
Jon
I replied to this in .programming. Please don't multipost. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Jonathan Porter" <JonathanPorter@.discussions.microsoft.com> wrote in message
news:D72A8997-D492-49A4-86DB-16C786771F3F@.microsoft.com...
> Hello- I have a C++ .NET application that rips through a raw file, generating
> thousands of INSERT statements to insert into a SQL Server 2000 database
> through the SQLConnection class in .NET. While this seems reasonably fast,
> I'm wondering if it is the most efficient way of doing this. Would creating
> a stored procedure on the SQL Server and then passing parameters to the SP
> through the Command object be faster and more efficient? I've also
> considered dumping the contents to a flat CSV file and using SQL Server DTS
> to BULK INSERT the rows- but that is additional overhead in creating the CSV
> file and then launching DTS etc. Any suggestions/comments would be
> appreciated.
> Thanks,
> Jon

Wednesday, February 15, 2012

Editing SQL Jobs

I have scheduled a T-SQL job that runs every morning using Enterprise Manager. Now I want to change the SELECT and UPDATE statements that this job runs, but I can't find anywhere to edit a job that has already been scheduled. Any help would be appreciated.

ThanksIn Enterprise Manager, under your SQL Server
-- expand the Management node
-- expand the SQL Server Agent node
-- click on Jobs
-- right-click on your job and choose Properties
-- click on the Steps tab
-- click on the desired Step and choose Edit...

Terri