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.
| 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 ONGOSET QUOTED_IDENTIFIER ONGOALTER procedure [dbo].[ListSearchZMVoorzieningen] @CSVInstellingID varchar(1000) = '',@InstellingNaam varchar(25) = '',@PlaatsNaam varchar(25) = '',@SorteerKolom varchar(25) = '',@SorteerVolgorde varchar(4) = '', @NetwerkID int = Null,@InstellingSoortCatWeergave int = 1asbegin 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 ENDendGOSET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER OFFGONow 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 ONGOSET QUOTED_IDENTIFIER ONGOALTER procedure [dbo].[ListSearchZMVoorzieningen] @CSVInstellingID varchar(1000) = '',@InstellingNaam varchar(25) = '',@PlaatsNaam varchar(25) = '',@SorteerKolom varchar(25) = '',@SorteerVolgorde varchar(4) = '', @NetwerkID int = Null,@InstellingSoortCatWeergave int = 1asbegin 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 ENDendGOSET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER OFFGOBut then when I try to run this, SQL Server says:Msg 457, Level 16, State 1, Procedure ListSearchZMVoorzieningen, Line 18Implicit 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: beginSo 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. |
 |
|
|
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? |
 |
|
|
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 |
 |
|
|
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. |
 |
|
|
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? |
 |
|
|
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? |
 |
|
|
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 ASCAnd not like thiscase @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 |
 |
|
|
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? |
 |
|
|
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 - sensitiveDo you know what I should choose? |
 |
|
|
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. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
|
|
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! |
 |
|
|
|
|
|
|
|