Showing posts with label executed. Show all posts
Showing posts with label executed. Show all posts

Sunday, February 19, 2012

how to check whether sql statement is executed

Hi,
I have a few sql statements in asp. How do I check that the first sql statement is executed before the second one? If the first sql statement does not execute, then the second one will not execute too.Varierty of ways...
What queries are we talking about... can you post them? Are we talking SELECTs or UPDATE/DELETEs ?|||Originally posted by autumn6
Hi,

I have a few sql statements in asp. How do I check that the first sql statement is executed before the second one? If the first sql statement does not execute, then the second one will not execute too.

May be @.@.ROWCOUNT (Returns the number of rows affected by the last statement) will help you to find decision. You can get value from ADO.|||how about a stored procedure that has all the statements with an IF after the first one?|||Originally posted by LFN
Varierty of ways...
What queries are we talking about... can you post them? Are we talking SELECTs or UPDATE/DELETEs ?

It's a few INSERT statements.|||Its my understading that an INSERT operation will either succeed - or fail with an error (not necessarily a fatal error though)

So if its just INSERTS youre doing then check for a non-fatal error. Obviously a fatal error will abort your code anyway.

You might want to consider using a transaction... just to make sure they all go - or none as required...

Then after each INSERT do the error check...

IF (@.@.ERROR <> 0) ... [ take action - maybe a goto error routine ].....

That will catch any non-fatal errors - if there wasnt one the INSERT worked.

LFN

How to check whether SQL login exists?

Is there any way to check whether the login exists before creating login ?

create login should be executed after check.

thanks,

Sreenath

Try something like this:

DECLARE @.SqlStatement nvarchar(4000)
Declare @.loginName varchar (100)

Select @.loginName = 'test\thermanson'

If not Exists (select loginname from master.dbo.syslogins where name = @.loginName and dbname = 'PUBS')
Begin

Set @.SqlStatement = 'CREATE LOGIN [' + @.loginName + '] FROM WINDOWS WITH DEFAULT_DATABASE=[PUBS], DEFAULT_LANGUAGE=[us_english]'

EXEC sp_executesql @.SqlStatement
End