Hi Experts,I have a table and on top of that I am running a SQL query to get the average calculations. The SQL query working fine without any issues,The problem is I would like this SQL Query to be converted as SQL Function so that I can run this in a easy way on multiple tables.Step 1:- ---SQL Table Structure:USE [abc]GOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[IC_Raw_In]( [I_Date] [varchar](50) NULL, [I_O_P] [money] NULL, [I_O_H] [money] NULL, [I_O_L] [money] NULL, [I_C_O] [money] NULL, [I_Serial] [numeric](18, 0) NULL) ON [PRIMARY]GOSET ANSI_PADDING OFFGO
Step2:----SQL Query for Average:WITH RankedPricesAS(SELECT i_serial , I_C_O, ROW_NUMBER() OVER (ORDER BY i_serial) AS rnFROM IC_Raw_In) SELECT a.i_serial, AVG(b.I_C_O) AS avgs FROM RankedPrices AS a LEFT JOIN RankedPrices AS b ON b.rn BETWEEN a.rn-11 AND a.rn GROUP BY a.i_serial
Step3:-- Looking for help to create based on Step 2 Query as a functionThanks,JJ