##First study how to handle data using a CURSOR ##
--Code Start
DECLARE get_Details CURSOR FOR
CREATE TABLE #Temp(Stu_id bigint,
Stu_No nvarchar,
Stu_Name nvarchar)
OPEN get_Details
DECLARE @id bigint
DECLARE @Stu_No nvarchar(64)
DECLARE @Stu_Name nvarchar(100)
FETCH NEXT FROM get_Details INTO @Stu_NO
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @id =id,@Stu_NO = NO,@Stu_Name = firstname,FROM aca_User WHERE id = @Stu_NO
INSERT INTO #Temp ( Stu_id,Stu_NO,Stu_Name) VALUES (@id,@Stu_NO,@Stu_Name)
FETCH NEXT FROM get_Details INTO @Stu_NO END
CLOSE get_Details
DEALLOCATE get_Details
SELECT * FROM #Temp
--Code is End
##Then know about that the same thing can do without using sql Cursor's
Because the cursor want higher memory usage of the RAM & then it produced more lower performance##
drop table EMPLOYEE2
SELECT ROWID=IDENTITY(int,1,1),userid
INTO EMPLOYEE2 FROM aca_role_assignments WHERE (roleid = @roleid) AND (contextid = @contexid) ORDER BY id
declare @rowcount int,
@counter int
SET @rowcount = (SELECT count(userid) FROM aca_role_assignments
WHERE (roleid =@roleid) AND (contextid = @contexid))
CREATE TABLE #Temp( Stu_id bigint,
Stu_NO nvarchar(100), Stu_Name nvarchar(100))
DECLARE @id bigint
DECLARE @Stu_NO nvarchar(100)
DECLARE @Stu_Name nvarchar(100)
set @counter = 1
while @counter <= @rowcount begin SELECT @id =id, @Stu_NO = firstname, @Stu_Name = lastname, from aca_user where id =(SELECT userid FROM EMPLOYEE2 WHERE ROWID=@counter) INSERT INTO #Temp ( Stu_id, Stu_NO,Stu_Name) VALUES (@id, @Stu_NO,@Stu_Name) set @counter = @counter + 1 end DELETE FROM aca_StudentSpecficCourse SELECT * FROM #Temp
Subscribe to:
Post Comments (Atom)
SQL Query Stuff
1 . By using this query can search any string contain within stored procedure, function or view SELECT object_name(id) FROM sys.sysc...
-
සන්නාහ සන්නද්ධ බලකාය කාලතුවක්කු හමූදාව ඉංජිනේරු බලකාය සංඥා බලකාය පාබල හමූදාව සිංහ රෙජිමේන්තුව ගැමූණූ හේවා බලකාය ගජබා රෙජිමේන්තුව වි...
-
" සිංහලේ ස්වාධීනත්වය යළිත් ළඟාකර දීමට සිංහලේ අනෙක් නායකයන් සමඟ එක් වී සටන් බිමට බැස්සෙමි . මවූබිම මූදා ලීමත් එමඟින් ...
-
USE THIS LINK. This site is maintain under ICTA Project: http://siyabas.lk/sinhala_how_to_install.html ONLINE KEYBOARD: http://www.ucsc.cmb....
No comments:
Post a Comment