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.
| 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 |
|
|
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 shotMaybe 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.ExampleTABLE-FeatureName-Status-Licensed-TurnedOnresults = 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-----> |
 |
|
|
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"; |
 |
|
|
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 ShawSQL Server MVP |
 |
|
|
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 ShawSQL Server MVP
PostgreSQL. |
 |
|
|
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 ShawSQL Server MVP |
 |
|
|
|
|
|