Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 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
Aged Yak Warrior

Romania
545 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
Aged Yak Warrior

Romania
545 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  
 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.42 seconds. Powered By: Snitz Forums 2000