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
NelPosted Aug 3, 2012, 5:25 AM
Sudhakar ChaudharyPosted Aug 2, 2012, 5:03 AM
pass parameter to procedure as :::dateTimePicker1.Value.ToLongDateString()
Deepak VermaPosted Aug 1, 2012, 9:51 AM
Can you upload a file containing:
NelPosted Aug 1, 2012, 3:45 AM
exec presmetajSaldo
@idki=2,
@data='07/12/2012',
@saldo=4
as well, and the result is the same:(. Nothing changed
Pradip PandeyPosted Aug 1, 2012, 3:23 AM
exec presmetajSaldo
@idki=2,
@data='07/12/2012',
@saldo=4
NelPosted Aug 1, 2012, 3:20 AM
Running
exec presmetajSaldo
@idki=2,
@data='12.07.2012',
@saldo=4
I get "0 rows affected" without row
select saldo from Kasovizvestaj
Pradip PandeyPosted Aug 1, 2012, 2:56 AM
Format English(Unites States)
Short Date M/d/yyyy
Long Date dddd, MMMM dd,yyyy
After changing this, try to execute your SP.
NelPosted Aug 1, 2012, 2:47 AM
Pradip PandeyPosted Aug 1, 2012, 2:45 AM
NelPosted Aug 1, 2012, 2:40 AM
I tried with your suggestion, but
exec presmetajSaldo
@idki=1,
@data='2012.07.12',
@saldo=45
throws a message "0 rows affected"
NelPosted Aug 1, 2012, 2:36 AM
exec presmetajSaldo
@idki=1,
@data='2012-07-12',
@saldo=45
returns a message: "0 rows affected" again:(
Jignesh TrivediPosted Aug 1, 2012, 2:24 AM
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.
Pradip PandeyPosted Aug 1, 2012, 2:08 AM
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
NelPosted Aug 1, 2012, 1:50 AM
"0 rows affected".
Jignesh TrivediPosted Jul 31, 2012, 11:53 PM
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
NelPosted Jul 31, 2012, 8:47 AM
Jignesh TrivediPosted Jul 31, 2012, 8:40 AM
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.
NelPosted Jul 31, 2012, 8:23 AM
"(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 TrivediPosted Jul 31, 2012, 8:08 AM
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
NelPosted Jul 31, 2012, 6:43 AM
I tried with
exec presmetajSaldo
@idki=1,
@data='07.12.2012',
@saldo=45
but I got "0 rows affected":(
NelPosted Jul 31, 2012, 6:36 AM
This didn't help.When I excevute the sp
exec presmetajSaldo
@idki=1,
@data='2012.07.12',
@saldo=45
I get "0 rows affected."
Jignesh TrivediPosted Jul 31, 2012, 6:04 AM
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.
Pradip PandeyPosted Jul 31, 2012, 6:01 AM
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.
NelPosted Jul 31, 2012, 4:43 AM
Column name Data type allow nulls
idki int Unchecked
data datetime Checked
saldo decimal(11, 3) Checked
and it should be
Pradip PandeyPosted Jul 31, 2012, 4:02 AM
NelPosted Jul 31, 2012, 3:50 AM
Pradip PandeyPosted Jul 31, 2012, 3:41 AM
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.