Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Implicit conversion of varchar value to varchar

Author  Topic 

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2006-06-30 : 10:17:24
The thing is, I know a little about T-SQl, but not that much. So, I've got this stored procedure, someone else made and I tried to modify it.

I originally did this (sorry for the amount of code):


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[ListSearchZMVoorzieningen]

@CSVInstellingID varchar(1000) = '',
@InstellingNaam varchar(25) = '',
@PlaatsNaam varchar(25) = '',
@SorteerKolom varchar(25) = '',
@SorteerVolgorde varchar(4) = '',
@NetwerkID int = Null,
@InstellingSoortCatWeergave int = 1

as
begin
set nocount on

IF @NetwerkID = -1
BEGIN
select
pr.ProductID as ProductID,
pd.ProductDetailsAantalPlaatsen as AantalPlaatsen,
pd.ProductDetailsAantalPlaatsenVrij as PlaatsenVrij,
st.InstellingSoortNaam as InstellingSoort,
bi.BasisIndelingNaam as BasisIndeling,
lo.LocatieBezoekPlaatsnaam as Plaats,
i.InstellingNaam as InstellingNaam,
lo.LocatiehoofdNetwerkid as Netwerkid
from
ZMProduct pr
inner join ZMInstellingSoort st on (pr.ProductInstellingSoortID = st.InstellingSoortID)
inner join ZMBasisIndeling bi on (pr.ProductBasisIndelingID = bi.BasisIndelingID)
inner join ZMLocatie lo on (pr.ProductLocatieID = lo.LocatieID)
left join ZMProductDetails pd on (pr.ProductProductDetailsID = pd.ProductDetailsID)
inner join ZMInstelling i on (lo.LocatieInstellingID = i.InstellingID)
where
pr.ProductPublicatieStatus = 1
and st.InstellingSoortCategorie = @InstellingSoortCatWeergave
and ((@CSVInstellingID = '') or (st.InstellingSoortID in (Select convert(int,Value) from dbo.Split(@CSVInstellingID,','))))
and ((@InstellingNaam = '') or (i.InstellingNaam like '%' + @InstellingNaam + '%'))
and ((@PlaatsNaam = '') or (lo.LocatieBezoekPlaatsnaam like '%' + @PlaatsNaam + '%'))

order by

case @SorteerVolgorde
when 'DESC' then

case @SorteerKolom
when 'INSTELLING' then i.InstellingNaam
when 'INSTELLINGSOORT' then st.InstellingSoortNaam
end
end DESC,
case @SorteerVolgorde
when 'DESC' then
case @SorteerKolom
when 'PLAATSNAAM' then lo.LocatieBezoekPlaatsnaam
when 'AANTALPLAATSEN' then pd.ProductDetailsAantalPlaatsen
when 'PLAATSENVRIJ'then pd.ProductDetailsAantalPlaatsenVrij
end
end DESC,

case @SorteerVolgorde
when 'ASC' then

case @SorteerKolom
when 'INSTELLING' then i.InstellingNaam
when 'INSTELLINGSOORT' then st.InstellingSoortNaam
end
end ASC,
case @SorteerVolgorde
when 'ASC' then
case @SorteerKolom
when 'PLAATSNAAM' then lo.LocatieBezoekPlaatsnaam
when 'AANTALPLAATSEN' then pd.ProductDetailsAantalPlaatsen
when 'PLAATSENVRIJ'then pd.ProductDetailsAantalPlaatsenVrij
end
end ASC
end
ELSE
BEGIN
select
pr.ProductID as ProductID,
pd.ProductDetailsAantalPlaatsen as AantalPlaatsen,
pd.ProductDetailsAantalPlaatsenVrij as PlaatsenVrij,
st.InstellingSoortNaam as InstellingSoort,
bi.BasisIndelingNaam as BasisIndeling,
lo.LocatieBezoekPlaatsnaam as Plaats,
i.InstellingNaam as InstellingNaam,
lo.LocatiehoofdNetwerkid as Netwerkid
from
ZMProduct pr
inner join ZMInstellingSoort st on (pr.ProductInstellingSoortID = st.InstellingSoortID)
inner join ZMBasisIndeling bi on (pr.ProductBasisIndelingID = bi.BasisIndelingID)
inner join ZMLocatie lo on (pr.ProductLocatieID = lo.LocatieID)
left join ZMProductDetails pd on (pr.ProductProductDetailsID = pd.ProductDetailsID)
inner join ZMInstelling i on (lo.LocatieInstellingID = i.InstellingID)

where
pr.ProductPublicatieStatus = 1
and st.InstellingSoortCategorie = @InstellingSoortCatWeergave
and ((@CSVInstellingID = '') or (st.InstellingSoortID in (Select convert(int,Value) from dbo.Split(@CSVInstellingID,','))))
and ((@InstellingNaam = '') or (i.InstellingNaam like '%' + @InstellingNaam + '%'))
and ((@PlaatsNaam = '') or (lo.LocatieBezoekPlaatsnaam like '%' + @PlaatsNaam + '%'))
and ((lo.LocatiehoofdNetwerkid = @NetwerkID) or EXISTS (select * from ZMNetwerkPZProduct Where ZMNetwerkPZProduct.ProductID = pr.ProductID AND ZMNetwerkPZProduct.NetwerkPZID = @netwerkid))
order by

case @SorteerVolgorde
when 'DESC' then

case @SorteerKolom
when 'INSTELLING' then i.InstellingNaam
when 'INSTELLINGSOORT' then st.InstellingSoortNaam
end
end DESC,
case @SorteerVolgorde
when 'DESC' then
case @SorteerKolom
when 'PLAATSNAAM' then lo.LocatieBezoekPlaatsnaam
when 'AANTALPLAATSEN' then pd.ProductDetailsAantalPlaatsen
when 'PLAATSENVRIJ'then pd.ProductDetailsAantalPlaatsenVrij
end
end DESC,

case @SorteerVolgorde
when 'ASC' then

case @SorteerKolom
when 'INSTELLING' then i.InstellingNaam
when 'INSTELLINGSOORT' then st.InstellingSoortNaam
end
end ASC,
case @SorteerVolgorde
when 'ASC' then
case @SorteerKolom
when 'PLAATSNAAM' then lo.LocatieBezoekPlaatsnaam
when 'AANTALPLAATSEN' then pd.ProductDetailsAantalPlaatsen
when 'PLAATSENVRIJ'then pd.ProductDetailsAantalPlaatsenVrij
end
end ASC
END

end
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO


Now at the front end of the website, when I try to sort on Plaatsnaam, it would give an error:

"Conversion failed when converting the varchar value 'Breda' to data type int."

So I figured the SP should be:


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[ListSearchZMVoorzieningen]

@CSVInstellingID varchar(1000) = '',
@InstellingNaam varchar(25) = '',
@PlaatsNaam varchar(25) = '',
@SorteerKolom varchar(25) = '',
@SorteerVolgorde varchar(4) = '',
@NetwerkID int = Null,
@InstellingSoortCatWeergave int = 1

as
begin
set nocount on

IF @NetwerkID = -1
BEGIN
select
pr.ProductID as ProductID,
pd.ProductDetailsAantalPlaatsen as AantalPlaatsen,
pd.ProductDetailsAantalPlaatsenVrij as PlaatsenVrij,
st.InstellingSoortNaam as InstellingSoort,
bi.BasisIndelingNaam as BasisIndeling,
lo.LocatieBezoekPlaatsnaam as Plaats,
i.InstellingNaam as InstellingNaam,
lo.LocatiehoofdNetwerkid as Netwerkid
from
ZMProduct pr
inner join ZMInstellingSoort st on (pr.ProductInstellingSoortID = st.InstellingSoortID)
inner join ZMBasisIndeling bi on (pr.ProductBasisIndelingID = bi.BasisIndelingID)
inner join ZMLocatie lo on (pr.ProductLocatieID = lo.LocatieID)
left join ZMProductDetails pd on (pr.ProductProductDetailsID = pd.ProductDetailsID)
inner join ZMInstelling i on (lo.LocatieInstellingID = i.InstellingID)
where
pr.ProductPublicatieStatus = 1
and st.InstellingSoortCategorie = @InstellingSoortCatWeergave
and ((@CSVInstellingID = '') or (st.InstellingSoortID in (Select convert(int,Value) from dbo.Split(@CSVInstellingID,','))))
and ((@InstellingNaam = '') or (i.InstellingNaam like '%' + @InstellingNaam + '%'))
and ((@PlaatsNaam = '') or (lo.LocatieBezoekPlaatsnaam like '%' + @PlaatsNaam + '%'))

order by

case @SorteerVolgorde
when 'DESC' then

case @SorteerKolom
when 'INSTELLING' then i.InstellingNaam
when 'INSTELLINGSOORT' then st.InstellingSoortNaam
when 'PLAATSNAAM' then lo.LocatieBezoekPlaatsnaam
end
end DESC,
case @SorteerVolgorde
when 'DESC' then
case @SorteerKolom
when 'AANTALPLAATSEN' then pd.ProductDetailsAantalPlaatsen
when 'PLAATSENVRIJ'then pd.ProductDetailsAantalPlaatsenVrij
end
end DESC,

case @SorteerVolgorde
when 'ASC' then

case @SorteerKolom
when 'INSTELLING' then i.InstellingNaam
when 'INSTELLINGSOORT' then st.InstellingSoortNaam
when 'PLAATSNAAM' then lo.LocatieBezoekPlaatsnaam
end
end ASC,
case @SorteerVolgorde
when 'ASC' then
case @SorteerKolom
when 'AANTALPLAATSEN' then pd.ProductDetailsAantalPlaatsen
when 'PLAATSENVRIJ'then pd.ProductDetailsAantalPlaatsenVrij
end
end ASC
end
ELSE
BEGIN
select
pr.ProductID as ProductID,
pd.ProductDetailsAantalPlaatsen as AantalPlaatsen,
pd.ProductDetailsAantalPlaatsenVrij as PlaatsenVrij,
st.InstellingSoortNaam as InstellingSoort,
bi.BasisIndelingNaam as BasisIndeling,
lo.LocatieBezoekPlaatsnaam as Plaats,
i.InstellingNaam as InstellingNaam,
lo.LocatiehoofdNetwerkid as Netwerkid
from
ZMProduct pr
inner join ZMInstellingSoort st on (pr.ProductInstellingSoortID = st.InstellingSoortID)
inner join ZMBasisIndeling bi on (pr.ProductBasisIndelingID = bi.BasisIndelingID)
inner join ZMLocatie lo on (pr.ProductLocatieID = lo.LocatieID)
left join ZMProductDetails pd on (pr.ProductProductDetailsID = pd.ProductDetailsID)
inner join ZMInstelling i on (lo.LocatieInstellingID = i.InstellingID)

where
pr.ProductPublicatieStatus = 1
and st.InstellingSoortCategorie = @InstellingSoortCatWeergave
and ((@CSVInstellingID = '') or (st.InstellingSoortID in (Select convert(int,Value) from dbo.Split(@CSVInstellingID,','))))
and ((@InstellingNaam = '') or (i.InstellingNaam like '%' + @InstellingNaam + '%'))
and ((@PlaatsNaam = '') or (lo.LocatieBezoekPlaatsnaam like '%' + @PlaatsNaam + '%'))
and ((lo.LocatiehoofdNetwerkid = @NetwerkID) or EXISTS (select * from ZMNetwerkPZProduct Where ZMNetwerkPZProduct.ProductID = pr.ProductID AND ZMNetwerkPZProduct.NetwerkPZID = @netwerkid))
order by

case @SorteerVolgorde
when 'DESC' then

case @SorteerKolom
when 'INSTELLING' then i.InstellingNaam
when 'INSTELLINGSOORT' then st.InstellingSoortNaam
when 'PLAATSNAAM' then lo.LocatieBezoekPlaatsnaam
end
end DESC,
case @SorteerVolgorde
when 'DESC' then
case @SorteerKolom
when 'AANTALPLAATSEN' then pd.ProductDetailsAantalPlaatsen
when 'PLAATSENVRIJ'then pd.ProductDetailsAantalPlaatsenVrij
end
end DESC,

case @SorteerVolgorde
when 'ASC' then

case @SorteerKolom
when 'INSTELLING' then i.InstellingNaam
when 'INSTELLINGSOORT' then st.InstellingSoortNaam
when 'PLAATSNAAM' then lo.LocatieBezoekPlaatsnaam
end
end ASC,
case @SorteerVolgorde
when 'ASC' then
case @SorteerKolom
when 'AANTALPLAATSEN' then pd.ProductDetailsAantalPlaatsen
when 'PLAATSENVRIJ'then pd.ProductDetailsAantalPlaatsenVrij
end
end ASC
END

end
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO


But then when I try to run this, SQL Server says:

Msg 457, Level 16, State 1, Procedure ListSearchZMVoorzieningen, Line 18
Implicit conversion of varchar value to varchar cannot be performed because the collation of the value is unresolved due to a collation conflict.

Line 18 is:

begin


So since my t-sql is no good, can someone please try and explain what this all means....

nr
SQLTeam MVY

12543 Posts

Posted - 2006-06-30 : 10:34:46
It means that you are comparing or setting a varchar value with another of a different collation.
It usually happens if you have a database with a different collation from the server and try to use temporary tables - but it could be because someone has specified a collation on a table.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2006-06-30 : 10:46:18
Could it be because I restored the db locally on a different SQL server (well they both are default sql express 2005 installs).
So what should I do now?
Go to Top of Page

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2006-06-30 : 10:49:53
By the way there are no temp tables involved, and I don;t think someone has specified a collation on a table
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-06-30 : 10:50:51
Check the collations of the database you restored and master - if they are different you will find a lot of problems - I would reinstall with the collation you need.

Otherwise you will have to specify explicit collations in queries.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2006-06-30 : 10:58:33
Yes, the default collation settings of the servers are different. My local one has Latin1_General_CI_AS and the production one has SQL_Latin1_General_CP1_CI_AS. Guess someone has been fooling around (perhaps it was me, I don't know)

What do you recommend for the default server setting?
Go to Top of Page

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2006-06-30 : 11:03:34
Or do you think I can just apply the change on the production server since the collation there should be ok?
Go to Top of Page

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2006-06-30 : 11:07:21
Can you explain why it has to be like this:

case @SorteerVolgorde
when 'ASC' then
case @SorteerKolom
when 'INSTELLING' then i.InstellingNaam
when 'INSTELLINGSOORT' then st.InstellingSoortNaam
end
end ASC,

case @SorteerVolgorde
when 'ASC' then
case @SorteerKolom
when 'PLAATSNAAM' then lo.LocatieBezoekPlaatsnaam
when 'AANTALPLAATSEN' then pd.ProductDetailsAantalPlaatsen
when 'PLAATSENVRIJ'then pd.ProductDetailsAantalPlaatsenVrij
end
end ASC


And not like this

case @SorteerVolgorde
when 'ASC' then
case @SorteerKolom
when 'INSTELLING' then i.InstellingNaam
when 'INSTELLINGSOORT' then st.InstellingSoortNaam
when 'PLAATSNAAM' then lo.LocatieBezoekPlaatsnaam
when 'AANTALPLAATSEN' then pd.ProductDetailsAantalPlaatsen
when 'PLAATSENVRIJ'then pd.ProductDetailsAantalPlaatsenVrij
end
end ASC
Go to Top of Page

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2006-07-03 : 03:32:51
If I try to change the stored procedure on the server I get the same error. Could you please tell me what to do? I don't really know.
Can you explain what is going on?
Go to Top of Page

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2006-07-13 : 05:22:48
Nigel, I'm trying to install SQL Express with SQL_Latin1_General_CP1_CI_AS, but during the install I can only select Latin1_General and then there are some options:
- Binary
- Case - sensitive
- Accent - sensitive
- Binary - code point
- Kana - sensitive
- Width - sensitive

Do you know what I should choose?
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-13 : 05:33:05
CI_AS stands for case insensitive, accent sensitive.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-13 : 05:39:19
Continuing at
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=69031

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

trouble2
Constraint Violating Yak Guru

267 Posts

Posted - 2006-07-13 : 11:24:33
IT WORKED!!!
I changed the collations of several columns and now I could change the Stored Procedure!
Go to Top of Page
   

- Advertisement -