Click here to Skip to main content
15,910,009 members
Home / Discussions / Database
   

Database

 
GeneralRe: Get error description (message) associated with @@Error Pin
Dan_P2-May-05 15:22
Dan_P2-May-05 15:22 
GeneralRe: Get error description (message) associated with @@Error Pin
_J_2-May-05 21:59
_J_2-May-05 21:59 
Generalpicture box binding problem Pin
Binary01102-May-05 9:36
Binary01102-May-05 9:36 
GeneralRe: picture box binding problem Pin
Dan_P2-May-05 15:45
Dan_P2-May-05 15:45 
GeneralRe: picture box binding problem Pin
Binary01102-May-05 18:18
Binary01102-May-05 18:18 
GeneralRe: picture box binding problem Pin
Michael Potter3-May-05 8:54
Michael Potter3-May-05 8:54 
GeneralRe: picture box binding problem Pin
Binary01103-May-05 15:22
Binary01103-May-05 15:22 
GeneralSELECT COUNT into a variable Pin
Luis Alonso Ramos2-May-05 8:10
Luis Alonso Ramos2-May-05 8:10 
Hello,

I have the following stored procedure:
DECLARE @@Cuenta int;
SELECT @@Cuenta = COUNT(*) FROM Recibos_Reimpresiones GROUP BY ID_recibo HAVING (ID_recibo = @ID_recibo);
SET @@Cuenta = @@Cuenta + 1;

INSERT INTO dbo.Recibos_Reimpresiones (ID_recibo, Reimpresion, ID_sesion, FechaHora)
    VALUES (@ID_recibo, @@Cuenta, @ID_sesion, GETDATE())

UPDATE Recibos
    SET Reimpresiones = (@@Cuenta)
    WHERE (ID_recibo = @ID_recibo)
Basically what it's trying to do is to get the number of reprintings from the Recibos_Reimpresiones table. If should contain no rows (for a receipt) if it has only been printed once.

When I try to reprint a receipt, a record should be added to this table, stating the number of receipt, and the reprinting number (the first reprinting being one.) Also, the reprint count in the receipt record in Recibos should be updated.

But when I try to run this stored procedure, I get an error saying that the Reimpresion field of the Recibos_Reimpresiones table does not allow NULLs and that the record could not be inserted. That means that @@Cuenta is NULL, and it should be an integer.

So, anyone knows what's happening here? Does COUNT(*) return NULL instead of 0 if no records are present? Ideas on how to fix it?

Thanks!

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralRe: SELECT COUNT into a variable Pin
Christian Graus2-May-05 14:07
protectorChristian Graus2-May-05 14:07 
GeneralRe: SELECT COUNT into a variable Pin
Luis Alonso Ramos2-May-05 14:15
Luis Alonso Ramos2-May-05 14:15 
GeneralRe: SELECT COUNT into a variable Pin
Colin Angus Mackay2-May-05 20:03
Colin Angus Mackay2-May-05 20:03 
GeneralRe: SELECT COUNT into a variable Pin
Luis Alonso Ramos2-May-05 20:52
Luis Alonso Ramos2-May-05 20:52 
GeneralRe: SELECT COUNT into a variable Pin
Colin Angus Mackay2-May-05 22:32
Colin Angus Mackay2-May-05 22:32 
Generalinstall mysql Pin
Anonymous2-May-05 5:52
Anonymous2-May-05 5:52 
GeneralSimple JOIN in Access 2002 Pin
Larsenal1-May-05 13:30
Larsenal1-May-05 13:30 
GeneralRe: Simple JOIN in Access 2002 Pin
turbochimp2-May-05 2:35
turbochimp2-May-05 2:35 
GeneralRe: Simple JOIN in Access 2002 Pin
Larsenal2-May-05 8:00
Larsenal2-May-05 8:00 
QuestionHow to compare time Pin
Leelanga30-Apr-05 22:13
Leelanga30-Apr-05 22:13 
AnswerRe: How to compare time Pin
Alexey A Abramov3-May-05 9:09
Alexey A Abramov3-May-05 9:09 
GeneralRe: How to compare time Pin
Leelanga4-May-05 5:49
Leelanga4-May-05 5:49 
QuestionPossible to pass table as parametr to stored procedure??? Pin
_J_30-Apr-05 8:28
_J_30-Apr-05 8:28 
AnswerRe: Possible to pass table as parametr to stored procedure??? Pin
NewSilence30-Apr-05 18:52
NewSilence30-Apr-05 18:52 
GeneralRe: Possible to pass table as parametr to stored procedure??? Pin
_J_30-Apr-05 22:02
_J_30-Apr-05 22:02 
Questionhow to efficiently use dataset in large database? Pin
feyang30-Apr-05 2:24
feyang30-Apr-05 2:24 
AnswerRe: how to efficiently use dataset in large database? Pin
Colin Angus Mackay30-Apr-05 10:27
Colin Angus Mackay30-Apr-05 10:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.