SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 get last record
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ddtopgun
Starting Member

26 Posts

Posted - 08/28/2014 :  04:54:14  Show Profile  Reply with Quote
i have code below and i want to get the total record in the table and
save to output variable for passing to my program
but in my program always get result zero..
but if i test in sql i see the total record from table..


IF @StatementType = 'PKaryawan'
	BEGIN		
		
		SELECT	NIK, nmKaryawan
		FROM	(
		SELECT	NTILE(1000) OVER (ORDER BY IdKaryawan) AS [page],
				NIK, nmKaryawan
		FROM	dbo.Karyawan
		) AS dep
		WHERE	[page] = @pageNumber;
		
		--SET @TotalRecord='SELECT ROW_NUMBER() OVER(ORDER BY idKaryawan) as row from karyawan'
		SELECT @TotalRecord=COUNT(*) FROM Karyawan 		
		
	END 


tks..

stepson
Constraint Violating Yak Guru

Romania
431 Posts

Posted - 08/28/2014 :  06:10:34  Show Profile  Reply with Quote
This piece of code is in a stored procedure?

How you retrieve from DB ?
I guess that you have a parameter with out the "direction" specific OUTPUT

EXEC yourSP @val1, @val2 OUTPUT


sabinWeb MCP
Go to Top of Page

ddtopgun
Starting Member

26 Posts

Posted - 08/28/2014 :  20:58:14  Show Profile  Reply with Quote
yes the code in sp


ALTER PROCEDURE [dbo].[sp_Paging]
@pageNumber INT = 1,
@TotalRecord INT OUTPUT,
@StatementType varchar(20)

IF @StatementType = 'PKaryawan'
	BEGIN		
		
		SELECT	NIK, nmKaryawan
		FROM	(
		SELECT	NTILE(1000) OVER (ORDER BY IdKaryawan) AS [page],
				NIK, nmKaryawan
		FROM	dbo.Karyawan
		) AS dep
		WHERE	[page] = @pageNumber;
		
		--SET @TotalRecord='SELECT ROW_NUMBER() OVER(ORDER BY idKaryawan) as row from karyawan'
		SELECT @TotalRecord=COUNT(*) FROM Karyawan 		
		
	END 


and for my program code below sorry Out Of Topic for my program


 with dmDakom.spPaging do
          begin
            StoredProcName:='sp_Paging';
            Prepare;
            ParamByName('PageNumber').Value:=j;
            ParamByName('StatementType').AsString:='PKaryawan';
            LRecord:=ParamByName('TotalRecord').AsInteger;
            Label8.Caption:=IntToStr(LRecord);
          end;
          dmDakom.spPaging.Active:=True;


the result variable LRecord zero..???
Go to Top of Page

stepson
Constraint Violating Yak Guru

Romania
431 Posts

Posted - 08/29/2014 :  01:31:32  Show Profile  Reply with Quote
Hi,

This is delphi ( i think)
I don't see where you execute the statement.

 ExecProc; 
 Edit1.Text := ParamByname('PROJ_ID').AsString;



I don't know delphi , so could be ExecSQL; or Open;




sabinWeb MCP
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000