How to execute function in SQL Server 2008

0 votes

I created a function and tried to run it, however there were various issues.

CREATE FUNCTION dbo.Afisho_rankimin(@emri_rest int)
RETURNS int
AS
   BEGIN
       Declare @rankimi int
       Select @rankimi=dbo.RESTORANTET.Rankimi
       From RESTORANTET
       Where  dbo.RESTORANTET.ID_Rest=@emri_rest
       RETURN @rankimi
  END
  GO
    SELECT dbo.Afisho_rankimin(5)AS Rankimi
  GO

The errors:

Msg 2714, Level 16, State 3, Procedure Afisho_rankimin, Line 11
There is already an object named 'Afisho_rankimin' in the database.

Another msg:

Can not find column "dbo", or the user defined function, or aggregate "dbo.Afisho_rankimin", or the name is ambiguous

Can someone please help me with this? 

Sep 10, 2022 in Database by Kithuzzz
• 38,010 points
707 views

1 answer to this question.

0 votes

The function appears not to be being created since there appears to be another object named Afisho rankimin in your database. Try giving your function  another name. E.g.

CREATE FUNCTION dbo.Afisho_rankimin1(@emri_rest int)
RETURNS int
AS
   BEGIN
       Declare @rankimi int
       Select @rankimi=dbo.RESTORANTET.Rankimi
       From RESTORANTET
       Where  dbo.RESTORANTET.ID_Rest=@emri_rest
       RETURN @rankimi
  END
  GO

Note that you need to call this only once, not every time you call the function. After that try calling

SELECT dbo.Afisho_rankimin1(5) AS Rankimi 

I hope this helps you.

answered Sep 11, 2022 by narikkadan
• 63,420 points

Related Questions In Database

0 votes
0 answers

How to create a table from select query result in SQL Server 2008

I tried to build a table from ...READ MORE

Sep 2, 2022 in Database by Kithuzzz
• 38,010 points
640 views
0 votes
0 answers
0 votes
1 answer

How to delete duplicate rows in SQL Server?

CTEs and ROW_NUMBER can be combined together which will ...READ MORE

answered Feb 10, 2022 in Database by Vaani
• 7,020 points
592 views
0 votes
1 answer

How can we achieve excel ceiling function with significance value in SQL Server

If the underlying data types and rounding ...READ MORE

answered Apr 4, 2022 in Database by gaurav
• 23,260 points
694 views
0 votes
1 answer

Rename column SQL Server 2008

Use sp_rename EXEC sp_RENAME 'TableName.PreviousColumnName' , 'NewColumnName', 'COLUMN' See: SQL SERVER ...READ MORE

answered Feb 23, 2022 in Database by Vaani
• 7,020 points
413 views
0 votes
0 answers

How to update Identity Column in SQL Server?

With 200 records currently, I want to ...READ MORE

Aug 9, 2022 in Database by Kithuzzz
• 38,010 points
1,094 views
0 votes
0 answers

Simple DateTime sql query

How do I query the DateTime database ...READ MORE

Aug 12, 2022 in Database by Kithuzzz
• 38,010 points
428 views
0 votes
0 answers

Calculate time difference in minutes in SQL Server

I require the minutes-based time difference between ...READ MORE

Aug 13, 2022 in Database by Kithuzzz
• 38,010 points
992 views
0 votes
1 answer

How to extract only the year from the date in sql server 2008?

To obtain the year from the given ...READ MORE

answered Sep 15, 2022 in Database by narikkadan
• 63,420 points
511 views
0 votes
1 answer

How to Execute SQL Server Stored Procedure in SQL Developer?

You don't need EXEC clause. Simply use: proc_name ...READ MORE

answered Sep 16, 2022 in Database by narikkadan
• 63,420 points
1,683 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP