[UPHPU] OT: SQL question (MSSQL)

Steve Dibb steve at wonkabar.org
Wed Sep 6 21:50:48 MDT 2006


J M wrote:
> Do you know of any SQL techniques that takes a value (variable) sends it in
> to a subquery, applies conditions with the "WHERE" part of a select
> statement (in the subquery) then goes onto the next value until the entire
> query is done?  If you could give me some psuedo code from any rdbms that
> you are familiar with, I might be able to translate it to TSQL from there
> with the use of google.

Google for some mssql stored procedure examples.  That will help you.

And yes, you can do IF statements and set variables.

DECLARE @id int;
SET @int = (SELECT id FROM table);

IF (SELECT bar FROM table WHERE id = @int) = 1 BEGIN
	UPDATE foo;
	SELECT 1;
END
ELSE (SQL ..) BEGIN
	DELETE FOO;
	SELECT 0;
END

etc...


More information about the UPHPU mailing list