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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 get last record

Author  Topic 

ddtopgun
Starting Member

26 Posts

Posted - 2014-08-28 : 04:54:14
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

545 Posts

Posted - 2014-08-28 : 06:10:34
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 - 2014-08-28 : 20:58:14
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

545 Posts

Posted - 2014-08-29 : 01:31:32
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
   

- Advertisement -