|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
convert SQL code to Stored Proc
Dear All,
Lately i have started to convert my sql code to stored procedures, however i am still a bit new on this matter. I have the following Sql Statement which I wish to convert to a stored procedure:- SELECT MAX(" & id & ") As maxID FROM " & table where id and table are parameters that I am passing to this sql from a function which is called getMaxID for example, in the vb.net code i call it as follows:- getMaxID("personID", "persons") Can anyone tell me how to convert it to a Stored Proc please Thanks for your help and time Johann |
|
#2
|
|||
|
|||
|
MSSQL 2000
Code:
CREATE PROCEDURE [dbo].[GetMaxID] @ID VARCHAR(128), @TableName VARCHAR(128) AS DECLARE @SQLString VARCHAR(8000) SELECT @SQLString = 'SELECT MAX( ' + @ID + ' ) AS maxID FROM ' + @TableName EXEC ( @SQLString ) GO In MSSQL2000 column and table name maximum length is 128 chars. There is few methods to call stored procedure in MSSQL. You can call above stored procedure for example this way: Code:
exec GetMaxID 'personID', 'persons' |
|
#3
|
|||
|
|||
|
it's not exactly what i was after, however i decided to use the @identity after doing an insert
Thanks however for your help Johann |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > convert SQL code to Stored Proc |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|