| Author |
Topic |
|
pmccann1
Posting Yak Master
107 Posts |
Posted - 2009-01-07 : 07:44:25
|
| is it possible to run a stored procedure from a view then look at the table that has been created from the procedure? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-07 : 08:00:04
|
No. Not in the same statement.And a view can only have one SELECT statement.But you can try withSELECT *FROM OPENDATASOURCE(.., 'EXEC MyStoredProcedure) AS fI think what you need is a table function. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2009-01-07 : 08:03:24
|
| Umh...what? You can have a procedure that creates a view but not the other way around. That just doesn't make sense... What is it you actually want to achieve?- Lumbago |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-07 : 08:51:14
|
quote: Originally posted by pmccann1 is it possible to run a stored procedure from a view then look at the table that has been created from the procedure?
can i ask the purpose for such a requirement? |
 |
|
|
pmccann1
Posting Yak Master
107 Posts |
Posted - 2009-01-07 : 09:41:19
|
| Bascially say i have the follwoing informationid course dept status1 edexcel lit 12 geog sci 52 maths sci 7i want one instance of each, as in one row for id 1 and one row for id 2 either of the ones that are there. the user that want this information can only use views that they have been give permission to. there is already a sp that does something likethis so i was just going to use it.suggestions to what way i could do it are welcome, could this just be done in a view only |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-07 : 09:45:30
|
quote: Originally posted by pmccann1 Bascially say i have the follwoing informationid course dept status1 edexcel lit 12 geog sci 52 maths sci 7i want one instance of each, as in one row for id 1 and one row for id 2 either of the ones that are there. the user that want this information can only use views that they have been give permission to. there is already a sp that does something likethis so i was just going to use it.suggestions to what way i could do it are welcome, could this just be done in a view only
yup. you can do this in view itself. just use like belowCREATE VIEW YourviewASSELECT t.id,t.course,t.dept,t.statusFROM YourTable tINNER JOIN (SELECT id,MAX(status) AS MaxStatus FROM YourTable GROUP BY id) t1ON t1.id=t.idAND t1.MaxStatus=t.status |
 |
|
|
pmccann1
Posting Yak Master
107 Posts |
Posted - 2009-01-07 : 10:19:52
|
this is the actual sql select statement will that work ok with thatSELECT DISTINCT dbo.stmbiogr.student_id, RIGHT(dbo.stmbiogr.student_id, 8) AS [Access No], dbo.stmaos.aos_code, dbo.stmaos.acad_period, dbo.stmaos.aos_period, dbo.stcsessd.aos_end_dt, dbo.stmaos.stage_code, dbo.stmaos.attend_mode, dbo.stmbiogr.forename, dbo.stmbiogr.surname, dbo.stmbiogr.birth_dt, dbo.stcstatd.full_descFROM dbo.stmbiogr INNER JOINdbo.stmaos ON dbo.stmbiogr.student_id = dbo.stmaos.student_id INNER JOIN dbo.stcstatd ON dbo.stmaos.aos_code = dbo.stcstatd.aos_code INNER JOIN dbo.stcsttyp ON dbo.stcstatd.aos_code = dbo.stcsttyp.aos_code INNER JOIN dbo.stcsessd ON dbo.stmaos.aos_code = dbo.stcsessd.aos_code AND dbo.stmaos.acad_period = dbo.stcsessd.acad_period AND dbo.stmaos.aos_period = dbo.stcsessd.aos_periodWHERE (dbo.stcsttyp.aos_type = 'C') AND (dbo.stmaos.acad_period = '08/09') AND (dbo.stmaos.stage_code = 'ENR') AND (dbo.stcsessd.geolocn_code IN ('D0001', 'C0001'))ORDER BY dbo.stmbiogr.student_id, dbo.stmaos.attend_mode, dbo.stcsessd.aos_end_dt |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-07 : 10:28:54
|
are you using sql 2005? then you can just useSELECT *FROM(SELECT ROW_NUMBER() OVER (PARTITION BY dbo.stmbiogr.student_id ORDER BY dbo.stcsessd.aos_end_dt DESC) AS RowNo,dbo.stmbiogr.student_id, RIGHT(dbo.stmbiogr.student_id, 8) AS [Access No], dbo.stmaos.aos_code, dbo.stmaos.acad_period, dbo.stmaos.aos_period, dbo.stcsessd.aos_end_dt, dbo.stmaos.stage_code, dbo.stmaos.attend_mode, dbo.stmbiogr.forename, dbo.stmbiogr.surname, dbo.stmbiogr.birth_dt, dbo.stcstatd.full_descFROM dbo.stmbiogr INNER JOINdbo.stmaos ON dbo.stmbiogr.student_id = dbo.stmaos.student_id INNER JOINdbo.stcstatd ON dbo.stmaos.aos_code = dbo.stcstatd.aos_code INNER JOINdbo.stcsttyp ON dbo.stcstatd.aos_code = dbo.stcsttyp.aos_code INNER JOINdbo.stcsessd ON dbo.stmaos.aos_code = dbo.stcsessd.aos_code AND dbo.stmaos.acad_period = dbo.stcsessd.acad_period AND dbo.stmaos.aos_period = dbo.stcsessd.aos_periodWHERE (dbo.stcsttyp.aos_type = 'C') AND (dbo.stmaos.acad_period = '08/09') AND (dbo.stmaos.stage_code = 'ENR') AND (dbo.stcsessd.geolocn_code IN ('D0001', 'C0001')))tWHERE RowNo=1ORDER BY student_id, attend_mode, aos_end_dt |
 |
|
|
pmccann1
Posting Yak Master
107 Posts |
Posted - 2009-01-07 : 10:42:02
|
| I am using sql2005 but when i use the above it says theSELECT ROW_NUMBER() OVER is not supported |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-07 : 11:50:08
|
You have to change the compatibility level to 90 or more. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-07 : 11:59:27
|
quote: Originally posted by pmccann1 I am using sql2005 but when i use the above it says theSELECT ROW_NUMBER() OVER is not supported
what does this return?EXEC sp_dbcmptlevel 'your db' |
 |
|
|
|