Computing.Net > Forums > Database > assign value to stored pro in SQL server

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

assign value to stored pro in SQL server

Reply to Message Icon

Name: sumaira
Date: May 4, 2009 at 02:10:19 Pacific
OS: Windows XP
Subcategory: General
Comment:

dear all,
i have made a stored procedure to generate auto id . when iexecute the pro i get folowing error:
Incorrect syntax near '0'. at the highlighted line .if i comment this line then i get this error:

Could not find stored procedure 'GRN'. at the last line.I don know the real problem.my procedure is here.
ALTER PROCEDURE mp_GenerateID
@tableName as varchar(50)='GRN_PART_MASTER'

AS
BEGIN
declare @Dt varchar(max);
declare @ID varchar(max);
declare @mMonth varchar(max);
select @Dt = 'Select GetDate()';
if @tableName = 'GRN_PART_MASTER'
begin
set @ID = 'Select GRNID from GRN_PART_MASTER ORDER BY GRNID DESC'
IF @ID <> ''
if Substring(@ID ,6, 2) = substring(convert(varchar,datepart(year,GETDATE())),3,2)
begin
set @mMonth = 'Substring(ID ,8, 2)'
if len(datepart(month, GETDATE())) <> 2
if @mMonth = '0' + 'select datepart(month, GETDATE())'
set @ID = 'Substring(@ID ,1,11)' + 'cast( Substring(@ID ,11,3) as int)' + '1';
else if @mMonth = 'select datepart(month, GETDATE())'
set @ID = 'Substring(@ID ,1,11)' + 'cast( Substring(@ID ,11,3)as int) ' + '1';
else
goto GenID;
end
else
GenID:
if len(datepart(month, GETDATE())) <> 2
else
set @ID = 'GRN-1' + 'select substring(convert(varchar,datepart(year,GETDATE())),3,2)' + 'select substring(convert(varchar,datepart(month,GETDATE())),1,2)' + '/001';
end
EXEC (@ID)
END



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: assign value to stored pro in SQL server

Problem in inserting values to a table in SQL www.computing.net/answers/dbase/problem-in-inserting-values-to-a-table-in-sql/710.html

date format in SQL Server www.computing.net/answers/dbase/date-format-in-sql-server/238.html

SQL Server Reporting Services www.computing.net/answers/dbase/sql-server-reporting-services/722.html