Hi again Denis, thanks for sending me to this thread.
I think this thread was the one which triggered me to contact you.
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....