i have this table (using sqlserver 2012)
CREATE TABLE [dbo].[CustomerTransactions](
[TransactionNumber] [nvarchar](11) NOT NULL,
[TransactionDate] [date] NOT NULL,
[SLoc] [nvarchar](4) NOT NULL,
[CustId] [nvarchar](10) NOT NULL,
[IsProcessed] [bit] NOT NULL,
[IsCancelled] [bit] NOT NULL,
CONSTRAINT [PK_CustomerTransactions] PRIMARY KEY CLUSTERED
(
[TransactionNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
and this my function before validate
protected function beforeValidate() {
parent::beforeValidate();
if ($this->isNewRecord) {
$criteria = new CDbCriteria;
$criteria->select = 'TransactionNumber';
$criteria->limit = 10;
$criteria->order = 'TransactionNumber DESC';
$criteria->condition = 'LEFT( TransactionNumber, 5) = CONVERT(VARCHAR(5),GETDATE(),5)';
$last = $this->find($criteria);
if ($last) {
$nomorId = (int) substr($last->TransactionNumber, 5) + 1;
$nomorId = date('ymd') . '' . sprintf("%05d", $nomorId);
} else {
$nomorId = date('ymd') . '' . sprintf("%05d", 1);
}
$this->TransactionNumber = $nomorId;
}
return true;
}
i always get duplicate entry
anybody can help me??