4

I am having a table with name medium and there is a column name medium name and creation date i have created stored procedure to insert specific above two values .below is my stored procedure

alter procedure insertmediumproc
    @MediumName varchar(50) ,@CreationDate datetime
as 
begin
    insert into medium  (MediumName, CreationDate) values(@MediumName,getdate())
end

when i tried to insert values in table with command below:

exec insertmediumproc Nepali,getdate()

it is showing error below: Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ')'.

T I
  • 9,562
  • 3
  • 26
  • 49
Shaikh Nadeem
  • 105
  • 2
  • 4
  • 10

3 Answers3

3

If you always want the current date as the value for the CreationDate column you could use a default on the table and modify your proc to just take @mediumnamn as parameter. Or you could modify it to this:

alter procedure insertmediumproc @MediumName varchar(50)
as begin
insert into medium (MediumName, CreationDate) values (@MediumName,getdate())
end

That way you don't have to send the date as a parameter.

jpw
  • 43,521
  • 6
  • 61
  • 82
1

You forgot the quotes around Nepali

exec insertmediumproc 'Nepali', getdate()

And your insert statement should be

insert into medium (MediumName, CreationDate) 
values (@MediumName, @CreationDate)

And if you only need a date then you can change the parameter type from datetime to date

juergen d
  • 195,137
  • 36
  • 275
  • 343
  • still i am getting same error,My table contains Meium Id,MediumName, CreationDate,Status(default constraint already gvn to 1) – Shaikh Nadeem Mar 28 '13 at 11:13
1

You have a syntax error - you are not passing in a proper VARCHAR - you need to quote the value:

exec insertmediumproc 'Nepali',getdate()
Oded
  • 477,625
  • 97
  • 867
  • 998