Question : What is wrong with the scaler function

when i run it a get Incorrect syntax near the keyword 'RETURN'.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
USE [CopyOf_Bidtracer]
GO
/****** Object:  UserDefinedFunction [dbo].[sf_CalendarsFoldersView]    Script Date: 08/20/2010 15:34:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create FUNCTION [dbo].[sf_CalendarsFoldersView]
(
      -- Add the parameters for the function here
      @BidID varchar(35),  @companyID varchar(25), @IntCount int, @returnvalue INT, @returnstring varchar(25)
)

RETURNS INT
AS
BEGIN
	
	SELECT @returnvalue = dbo.sf_ReturnFolderCount(@BidID,@companyID, 'Plans' )


IF @returnvalue > 0
	SET @ReturnString = '<img alt = "cal-Plan" scr = "">'
ELSE
	SET  @ReturnString = ''
END

RETURN @ReturnString
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
USE [CopyOf_Bidtracer]
GO
/****** Object:  UserDefinedFunction [dbo].[sf_CalendarsFoldersView]    Script Date: 08/20/2010 15:34:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create FUNCTION [dbo].[sf_CalendarsFoldersView]
(
      -- Add the parameters for the function here
      @BidID varchar(35),  @companyID varchar(25), @IntCount int, @returnvalue INT, @returnstring varchar(25)
)

RETURNS INT
AS
BEGIN
	
	SELECT @returnvalue = dbo.sf_ReturnFolderCount(@BidID,@companyID, 'Plans' )


IF @returnvalue > 0
	SET @ReturnString = '<img alt = "cal-Plan" scr = "">'
ELSE
	SET  @ReturnString = ''
END

RETURN @ReturnString

Answer : What is wrong with the scaler function

Select DestID, Description, Addr1, Addr2, City, Deleted
FROM
(
     SELECT DestID, Description, Addr1, Addr2, City, Deleted,
--- row_number() - best to check books online
--- in brief, it allows you to analytically number the rows based on a particular order
--- you can also break up the data (partition), in this case each new description restarts the row number
      rn=row_number() over (partition by Description order by DestID desc)
     FROM tblDestination
     WHERE Description IS NOT NULL
       -- WHERE Description > ''   --- omit nulls and empty strings
       --and Deleted != 0  ---- assuming deleted is bit?
       and Deleted != 'false '  --- string 'false'
) SQ
--- this filters the subquery for where the rn value is 1, i.e. the first record in a partition
Where rn=1


To see what it actually does, run the below on its own

     SELECT DestID, Description, Addr1, Addr2, City, Deleted,
      rn=row_number() over (partition by Description order by DestID desc)
     FROM tblDestination
     WHERE Description IS NOT NULL
       -- WHERE Description > ''   --- omit nulls and empty strings
       --and Deleted != 0  ---- assuming deleted is bit?
       and Deleted != 'false '  --- string 'false'
     ORDER BY Description, DestID desc
Random Solutions  
 
programming4us programming4us