I have a stored procedure which when not inserted the row for date calculates correctly, but with it, the sp just takes the last enrtered value for saldo, instead of performing the calculation. Here is the sp:
ALTER procedure [dbo].[presmetajSaldo]
(
@idki int,
@data DateTime,
@saldo numeric(12,3) output
)
as
Declare @priem numeric(12,3)
Declare @isplata numeric(12,3)
select @priem = sum(iznosden) from blagajna_jspturs
where data=@data and vp>=0 and vp<=10
select @isplata = sum(iznosden)
from blagajna_jspturs
where vp>10 and data=@data
set @saldo = isnull(@saldo,0) + (isnull(@priem,0)) - (isnull(@isplata,0))
update Kasovizvestaj
set
idki=@idki,
saldo=@saldo
where data=@data ---this row is the problem
select saldo from Kasovizvestaj
return
Can anybody help me please? Thanks

Pradip PandeyRank #452 · 5.6K reputationPosted Jul 30, 2012, 11:41 PM EDT
You should cast the date where you are using in update statement i.e
update Kasovizvestaj
set
idki=@idki,
saldo=@saldo
where data=Cast(@data as varchar(12))
Hope it will help.
NelRank #2,060 · 702 reputationPosted Jul 30, 2012, 11:50 PM EDT
Pradip PandeyRank #452 · 5.6K reputationPosted Jul 31, 2012, 12:02 AM EDT
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 12:43 AM EDT
Column name Data type allow nulls
idki int Unchecked
data datetime Checked
saldo decimal(11, 3) Checked
and it should be
Pradip PandeyRank #452 · 5.6K reputationPosted Jul 31, 2012, 2:01 AM EDT
1 2012-07-11 00:00:00.000 45000.000
2 2012-07-12 00:00:00.000 45000.000
3 2012-07-20 00:00:00.000 45000.000
So I found that this problem is related with date format, I mean to say that while you execute SP like this
exec [presmetajSaldo] 2,'12/07/2012',0
It gives an error but in case of this
exec [presmetajSaldo] 2,'07/12/2012',0
runs fine
So, check your date format while you are passing as a parameter to execute SP.
Hope it will help.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 31, 2012, 2:04 AM EDT
Rewrite your update statement...
update Kasovizvestaj set saldo=@saldo
where data=@data and idki=@idki
I assume that there is unique value in idki.
can please provide details of input i mean to say parameter value when SP called?
thx.
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 2:36 AM EDT
This didn't help.When I excevute the sp
exec presmetajSaldo
@idki=1,
@data='2012.07.12',
@saldo=45
I get "0 rows affected."
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 2:43 AM EDT
I tried with
exec presmetajSaldo
@idki=1,
@data='07.12.2012',
@saldo=45
but I got "0 rows affected":(
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 31, 2012, 4:08 AM EDT
I tried self with sp and with out sp bot are working..
check below code in sql server. is it work?
Declare @data DateTime
Declare @saldo numeric(12,3)
set @data= '2012.07.12'
set @saldo = 5000
update Kasovizvestaj
set
saldo=@saldo
where data = @data
also are you use any spacial COLLATE in SQL Server?
can you please share create table script which is generated form SQL server?
thx
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 4:23 AM EDT
"(0 row(s) affected)"
Here is the create table script:
USE [Bl]
GO
/****** Object: Table [dbo].[Kasovizvestaj] Script Date: 07/31/2012 14:24:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Kasovizvestaj](
[idki] [int] NOT NULL,
[data] [datetime] NULL,
[saldo] [decimal](11, 3) NULL
) ON [PRIMARY]
GO
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 31, 2012, 4:40 AM EDT
Try with date which present in you db and also change style of date like 'yyyy-mm-dd' instead of 'yyyy.mm.dd'
hope this time it will work.
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 4:47 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 31, 2012, 7:53 PM EDT
Try following change
ALter procedure [dbo].[presmetajSaldo]
(
@idki int,
@data DateTime,
@saldo numeric(12,3) output
) as
Declare @priem numeric(12,3)
Declare @isplata numeric(12,3)
select @priem = sum(iznosden) from blagajna_jspturs
where data=@data and vp>=0 and vp<=10
select @isplata = sum(iznosden)
from blagajna_jspturs
where vp>10 and data=@data
set @saldo = isnull(@saldo,0) + (isnull(@priem,0)) - (isnull(@isplata,0))
update Kasovizvestaj
set
saldo=@saldo
where CONVERT(VARCHAR(10),data,104) = CONVERT(VARCHAR(10),@data,104)
return
run this code...
exec presmetajSaldo
@idki=1,
@data='2012-12-07',
@saldo=66
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 9:50 PM EDT
"0 rows affected".
Pradip PandeyRank #452 · 5.6K reputationPosted Jul 31, 2012, 10:08 PM EDT
try this..
ALTER procedure [dbo].[presmetajSaldo]
(
@idki int,
@data varchar(12),
@saldo numeric(12,3) output
)
as
Declare @priem numeric(12,3)
Declare @isplata numeric(12,3)
select @priem = sum(iznosden) from blagajna_jspturs
where data=cast(@data as varchar(12)) and vp>=0 and vp<=10
select @isplata = sum(iznosden)
from blagajna_jspturs
where vp>10 and data=cast(@data as varchar(12))
set @saldo = isnull(@saldo,0) + (isnull(@priem,0)) - (isnull(@isplata,0))
update Kasovizvestaj
set
idki=@idki,
saldo=@saldo
where data=cast(@data as varchar(12))
select saldo from Kasovizvestaj
return
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 31, 2012, 10:24 PM EDT
replace following line with update statement of your sp..
are you use sql server 2008?
update Kasovizvestaj
set saldo=@saldo
where cast(data as date) = cast(@data as date)
please make sure when you pass from C# application you must truncate time from datetime format
let us know the result.
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 10:36 PM EDT
exec presmetajSaldo
@idki=1,
@data='2012-07-12',
@saldo=45
returns a message: "0 rows affected" again:(
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 10:40 PM EDT
I tried with your suggestion, but
exec presmetajSaldo
@idki=1,
@data='2012.07.12',
@saldo=45
throws a message "0 rows affected"
Pradip PandeyRank #452 · 5.6K reputationPosted Jul 31, 2012, 10:45 PM EDT
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 10:47 PM EDT
Pradip PandeyRank #452 · 5.6K reputationPosted Jul 31, 2012, 10:56 PM EDT
Format English(Unites States)
Short Date M/d/yyyy
Long Date dddd, MMMM dd,yyyy
After changing this, try to execute your SP.
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 11:20 PM EDT
Running
exec presmetajSaldo
@idki=2,
@data='12.07.2012',
@saldo=4
I get "0 rows affected" without row
select saldo from Kasovizvestaj
Pradip PandeyRank #452 · 5.6K reputationPosted Jul 31, 2012, 11:23 PM EDT
exec presmetajSaldo
@idki=2,
@data='07/12/2012',
@saldo=4
NelRank #2,060 · 702 reputationPosted Jul 31, 2012, 11:45 PM EDT
exec presmetajSaldo
@idki=2,
@data='07/12/2012',
@saldo=4
as well, and the result is the same:(. Nothing changed
Deepak VermaRank #672 · 3.6K reputationPosted Aug 1, 2012, 5:51 AM EDT
Can you upload a file containing:
Sudhakar ChaudharyRank #1,379 · 1.2K reputationPosted Aug 2, 2012, 1:03 AM EDT
pass parameter to procedure as :::dateTimePicker1.Value.ToLongDateString()
NelRank #2,060 · 702 reputationPosted Aug 3, 2012, 1:25 AM EDT