stored procedures - conversion failed when converting [T-SQL / SQL Server] -


everytime try call stored procedure, following error:

msg 245, level 16, state 1, procedure p_kb_get_gk_uebersicht, line 16

conversion failed when converting varchar value 'diverse' data type int.

some sample values (or sample call) looks this:

exec p_kb_get_gk_uebersicht '','','','','d2335548','','lindner',''

i don't understand error-message @ all. refering diverse. also, possibly go wrong converting int? 2nd , last parameter int, without single quotes, error-message stays same.

just give information, i'll add stored procedure.

go set ansi_nulls on go set quoted_identifier on go  alter procedure [dbo].[p_kb_get_gk_uebersicht] @status tinyint, @jahr int, @cl_vnr bigint, @cl_name nvarchar(50), @sgi nvarchar(20), @gknr nvarchar(4), @gkname varchar(50), @gueltjahr int   if @cl_vnr = '' set @cl_vnr = 0 if @status = '' set @status = 0 if @jahr = '' set @jahr = 0 if @gueltjahr = '' set @gueltjahr = '0' if @gknr = '' set @gknr = '0' if @gknr null set @gknr = '0'   if @gueltjahr = '0'     select distinct cl_id, cd_clvid, cd_version, cl_name, cd_jahr, st_name cd_status,         case isnull(cd_aktiv,0) when 0 'nein' when 1 'ja' end cd_aktiv,         cd_status cd_status_id, cd_von, cd_bis      dbo.v_kb_cluster d     inner join dbo.v_kb_cluster_gk k on d.cd_clvid = k.kd_clvid     left join dbo.t_kb_gk_status on cd_status = st_id       d.cl_art = 'gk'             , cd_status = case when @status = 0 cd_status else @status end             , cd_jahr = case when @jahr = 0 cd_jahr else @jahr end             , cd_clvid = case when @cl_vnr = 0 cd_clvid else @cl_vnr end             , cl_name '%' + @cl_name + '%'             , k.kd_nr = case when @gknr = '0' k.kd_nr else @gknr end             , k.gk_kunde '%' + @gkname + '%'     order cl_id, cd_jahr desc, cd_version desc else     select distinct cl_id, cd_clvid, cd_version, cl_name, cd_jahr, st_name cd_status,         case isnull(cd_aktiv,0) when 0 'nein' when 1 'ja' end cd_aktiv,         cd_status cd_status_id, cd_von, cd_bis      dbo.v_kb_cluster d     inner join dbo.v_kb_cluster_gk k on d.cd_clvid = k.kd_clvid     left join dbo.t_kb_gk_status on cd_status = st_id       d.cl_art = 'gk'             , cd_status = case when @status = 0 cd_status else @status end             , cd_jahr = case when @jahr = 0 cd_jahr else @jahr end             , cd_clvid = case when @cl_vnr = 0 cd_clvid else @cl_vnr end             , cl_name '%' + @cl_name + '%'             , k.kd_nr = case when @gknr = '0' k.kd_nr else @gknr end             , k.gk_kunde '%' + @gkname + '%'             , @gueltjahr between year(cd_von) , isnull(year(cd_bis),@gueltjahr)     order cl_id, cd_jahr desc, cd_version desc  

i'm using sql-server 2008.

update: doesn't work numerical values well:

exec p_kb_get_gk_uebersicht 0,0,0,'','d2335548','','lindner',0

your call stored procedure wrong. sql server expecting tinyint, int , bigint respectively first 3 parameters, passing '' interpreted varchar. looking @ proc, think need pass 3 0, if want default values.

edit

your sql wrong. replace

if @gueltjahr = '0' 

with

if @gueltjahr = 0 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -