Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select * with conditional stored procedure

Author  Topic 

kopo
Starting Member

4 Posts

Posted - 2012-01-20 : 13:44:34
I would like to execute a select * statement that could return multiple rows and conditionally update one of the columns based on data from other columns in that row with another stored procedure. Can this operation be done?

Something like:

SELECT * "SessInfo"

FOREACH row_returned modify row.column based on stored_procedure


It would be nice if I could execute this all in one command.

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-20 : 13:47:57
What Stored Procedure?

You can not perform an SELECT and an UPDATE in 1 shot

Maybe if you post some more details about what you are trying to do



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

kopo
Starting Member

4 Posts

Posted - 2012-01-20 : 13:58:27
quote:
Originally posted by X002548

What Stored Procedure?

You can not perform an SELECT and an UPDATE in 1 shot

Maybe if you post some more details about what you are trying to do




Sorry, I don't want to update the db, i want to update the returned results.

Use Case:
I would like to retrieve a list of session with associated data (each row) but conditional change the data that is returned based on data that is in the row.

Example
TABLE
-FeatureName
-Status
-Licensed
-TurnedOn


results = Select * from TABLE

<-----The following logic is in a SP----->
for(results[row];row++)
{
if(Licensed && TurnedOn)
results[row].Status = OK;
if(!TurnedOn)
results[row].Status = NOTON;
if(!Licensed)
results[row].Status = NOTLIC;
}
<----- END SP----->
Go to Top of Page

kopo
Starting Member

4 Posts

Posted - 2012-01-20 : 14:03:45
I can do it with when only one row is retrieved as such:


CREATE OR REPLACE FUNCTION "sp_get_feature_info"(par_devid character varying)
RETURNS "FeatureInfo" AS $$
DECLARE
_feature_info "FeatureInfo"%ROWTYPE;
BEGIN
SELECT * INTO _feature_info
FROM "FeatureInfo";

SELECT "sp_get_status"(_feature_info."FeatureID") INTO _feature_info."Status";

RETURN _feature_info;
END; $$ LANGUAGE 'plpgsql';
ALTER FUNCTION "sp_get_feature_info"(par_devid character varying) OWNER TO "postgres";
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-20 : 14:04:57
That's PostGreSQL, not T-SQL. What database engine are you using?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

kopo
Starting Member

4 Posts

Posted - 2012-01-20 : 14:12:19
quote:
Originally posted by GilaMonster

That's PostGreSQL, not T-SQL. What database engine are you using?

--
Gail Shaw
SQL Server MVP



PostgreSQL.
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-20 : 15:30:21
This is a Microsoft SQL Server forum, not a PostgreQL forum. As such the people here know Microsoft SQL Server. Maybe there's someone knows PostgreSQL, but it's not certain. Try posting this in a PostgreSQL forum, there's one at dbforums -> http://www.dbforums.com/postgresql/

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -