CREATE OR REPLACE FUNCTION CHI_X2 (a1 in number, b1 in number, a2 in number, b2 in number)
RETURN NUMBER IS
DECLARE @tr1 INT;
DECLARE @tr2 INT;
DECLARE @tc1 INT;
DECLARE @tc2 INT;
DECLARE @ca1 INT;
DECLARE @ca2 INT;
DECLARE @cb1 INT;
DECLARE @cb2 INT;
DECLARE @xi INT;
DECLARE @nt INT;
CREATE PROCEDURE ()
AS
BEGIN
SET tr1 = a1+b1
SET tr2 = a2+b2
SET tc1 = a1+a2
SET tc2 = b1+b2
SET nt = tr1+tr2
SET ca1 =(tc1/nt*tr1)
SET ca2 =(tc1/nt*tr2)
SET cb1 =(tc2/nt*tr1)
SET cb2 =(tc2/nt*tr2)
SET xi =((power((a1 -ca1),2)/ca1)+(power((a2 -ca2),2)/ca2)+(power((b1 -cb1),2)/cb1)+(power((b2-cb2),2)/cb2))
return xi
END CHI_X2
CREATE PROCEDURE ()
AS
begin
DECLARE @max_chi INT
DECLARE @xi INT
DECLARE @maxpos INT
DECLARE @n INT
DECLARE @SWV_CUR_OUT_sno VARCHAR(255)
DECLARE @SWV_CUR_OUT_p VARCHAR(255)
DECLARE @SWV_CUR_OUT_t VARCHAR(255)
DECLARE @SWV_cursor_var1 CURSOR
DECLARE @SWV_CUR_IN_sno VARCHAR(255)
DECLARE @SWV_CUR_IN_p VARCHAR(255)
DECLARE @SWV_CUR_IN_t VARCHAR(255)
delete from CH_TABLE
commit
SET @SWV_cursor_var1 = CURSOR FOR select sessionnumber, sessioncount, timespent from CH_TABLE
order by sessionnumber asc
OPEN @SWV_cursor_var1
FETCH NEXT FROM @SWV_cursor_var1 INTO
@SWV_CUR_OUT_sessionnumber,@SWV_CUR_OUT_sessioncount,@SWV_CUR_OUT_timespent
while @@FETCH_STATUS = 0
begin
SET @max_chi = -999
SET @maxpos = NULL
SET @SWV_cursor_var1 = CURSOR FOR select sessionnumber, sessioncount, timespent from CH_TABLE
order by sessionnumber asc
OPEN @SWV_cursor_var1
FETCH NEXT FROM @SWV_cursor_var1 INTO
@SWV_CUR_IN_sessionnumber,@SWV_CUR_IN_sessioncount,@SWV_CUR_IN_timespent
while @@FETCH_STATUS = 0
begin
select @n = count(*) from(select x1 as x from CH_TABLE union all select x2 from CH_TABLE) AS TabAl
where x = @SWV_CUR_OUT_sessionnumber or x = @SWV_CUR_IN_sessionnumber
if n = 0
begin
SET xi = round(CHI_X2(cur_out.sessioncount,cur_out.timespent,cur_in.sessioncount,cur_in.timespent),2)
if xi > max_chi
begin
SET max_chi = xi
SET maxpos = cur_in.sessionnumber
end
end
FETCH NEXT FROM @SWV_cursor_var1 INTO
@SWV_CUR_IN_sessionnumber,@SWV_CUR_IN_sessioncount,@SWV_CUR_IN_timespent
end
if max_chi > -999
begin
INSERT INTO CH_TABLE(X1, X2, VALUE)
VALUES(cur_out.sessionnumber, maxpos, max_chi)
commit
end
CLOSE @SWV_cursor_var1
FETCH NEXT FROM @SWV_cursor_var1 INTO
@SWV_CUR_OUT_sessionnumber,@SWV_CUR_OUT_sessioncount,@SWV_CUR_OUT_timespent
end
CLOSE @SWV_cursor_var1
END
Hye, there everyone, I'm new to everything here just need to that I have converted the following code into MS SQL SERVER 2008 from Oracle! Now it has some errors though I have done it and NEW to SQL SERVER 2008 Please correct my code;it has some errors! I don't know about how to get rid as I'm new! Please can somebody help me It will be a great effort like a teacher! I will be thankful! Thanks in advance...
Following Expected errors:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'OR'.
Msg 102, Level 15, State 1, Line 13
Incorrect syntax near '('.
Msg 102, Level 15, State 1, Line 17
Incorrect syntax near '='.
Msg 178, Level 15, State 1, Line 27
A RETURN statement with a return value cannot be used in this context.
Msg 102, Level 15, State 1, Line 28
Incorrect syntax near 'CHI_X2'.
Msg 134, Level 15, State 1, Line 36
The variable name '@xi' has already been declared. Variable names must be unique within a query batch or stored procedure.
Msg 137, Level 15, State 2, Line 49
Must declare the scalar variable "@SWV_CUR_OUT_sessionnumber".
Msg 137, Level 15, State 2, Line 56
Must declare the scalar variable "@SWV_CUR_IN_sessionnumber".
Msg 137, Level 15, State 2, Line 60
Must declare the scalar variable "@SWV_CUR_OUT_sessionnumber".
Msg 102, Level 15, State 1, Line 63
Incorrect syntax near '='.
Msg 102, Level 15, State 1, Line 66
Incorrect syntax near '='.
Msg 137, Level 15, State 2, Line 71
Must declare the scalar variable "@SWV_CUR_IN_sessionnumber".
Msg 137, Level 15, State 2, Line 83
Must declare the scalar variable "@SWV_CUR_OUT_sessionnumber".
Msg 102, Level 15, State 1, Line 86
Incorrect syntax near 'END'.