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 |
Gudea
Starting Member
18 Posts |
Posted - 2012-02-25 : 15:20:53
|
Hi.I am programming a Stored to list Entities (Countries, and others) in a multilanguage scenario.I have two tables for each translated entity plus Language list.LanguageLang_Id intLand_Name varcharLang_Defaut bitLang_Rquired bitCountryCoun_Id intCoun_ISO varcharCoun_Flag varcharCountryTr (Translation)CoTr_Id intCoTr_Coun_Id intCoTr_Lang_Id intCoTr_Name varchar (translated name for each Country)I am trying to program a stored that lists all Countries with the name of the specified language (if available) otherwise the name in the default (mandatory) language. Both with the obtained language reference.Its easy the first partCREATE PROCEDURE dbo.CountryList@Language_Id intASSELECTCoun_Id,Coun_ISO,CoTr_Name As Coun_Name,Lang_IdFROMCountryJOINCountryTrON CoTr_Coun_Id = Coun_IdJOINLanguageON Lang_Id = CoTr_Lang_IdWHERELang_Id = @Language_Id(Don't know if it is running, I just re-wroted it here manually)But I can't get the country if no translation is available for the specifyed languaje. Also I can't bring the default translation in that case.For instance an expected result would be:@Language_Id = 3 (spanish)Id ISO Name Lang1 US Estados Unidos 32 FR Francia 33 DE Germany 1 (no translation for Germany, English brought as default language)Please, I need some hint here.ThanksRegards |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-25 : 17:46:54
|
[code]CREATE PROCEDURE dbo.CountryList@Language_Id intASSELECTc.Coun_Id,c.Coun_ISO,ct.CoTr_Name As Coun_Name,COALESCE(l1.Lang_Id,l2.Lang_Id) AS Lang_IdFROMCountry cLEFT JOIN CountryTr ctON ct.CoTr_Coun_Id = c.Coun_IdLEFT JOIN Language l1ON l1.Lang_Id = ct.CoTr_Lang_IdCROSS JOIN Language l2ON l2.Lang_Defaut = 1WHERECOALESCE(l1.Lang_Id,l2.Lang_Id) = @Language_Id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
Gudea
Starting Member
18 Posts |
Posted - 2012-02-26 : 17:37:21
|
Wow thanks. CROSS JOIN...Anyway it is giving me an syntax error near the word ONON l2.Lang_Defaut = 1 <----- in this line.I checked twice for any typo...If I comment this line, it works, but without the expected results.Thanks in advance visakh |
 |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-02-26 : 18:03:45
|
Because CROSS JOIN doesn't have an ON clause. It should beCREATE PROCEDURE dbo.CountryList@Language_Id intASSELECTc.Coun_Id,c.Coun_ISO,ct.CoTr_Name As Coun_Name,COALESCE(l1.Lang_Id,l2.Lang_Id) AS Lang_IdFROMCountry cLEFT JOIN CountryTr ctON ct.CoTr_Coun_Id = c.Coun_IdLEFT JOIN Language l1ON l1.Lang_Id = ct.CoTr_Lang_IdCROSS JOIN Language l2WHERECOALESCE(l1.Lang_Id,l2.Lang_Id) = @Language_Id Cross join is explicitly a 'join' without matching columns, it all rows from one table to all from another.--Gail ShawSQL Server MVP |
 |
|
Gudea
Starting Member
18 Posts |
Posted - 2012-02-26 : 18:59:44
|
Ok, now it compiles, but I am not getting the expected resultsI can't see any reference to the default language now, so, I get:1 US Estados Unidos 31 US Estados Unidos 31 US Estados Unidos 32 FR Francia 32 FR Francia 32 FR Francia 3Three times each country but the one that doesn't have translation. a DISTINCT won't help here.If I add another WHERE conditionAND l2.Lang_Defaut = 1It shows once each country, but the one missing its translation.1 US Estados Unidos 32 FR Francia 3Missing: 3 DE Germany 1Sorry, but I can't get any idea what else to try.Thanks |
 |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-02-26 : 19:11:14
|
Can you post sample data please for all involved tables and the expected results for that sample data--Gail ShawSQL Server MVP |
 |
|
Gudea
Starting Member
18 Posts |
Posted - 2012-02-27 : 10:35:17
|
Here is a sample. I'll add logical deletion.TABLE: LanguageLang_Id intLand_Name varcharLang_Defaut bitLang_Rquired bitLang_Active bitTABLE: CountryCoun_Id intCoun_ISO varcharCoun_Flag varcharCoun_Active bitTABLE: CountryTr (Translation)CoTr_Id intCoTr_Coun_Id intCoTr_Lang_Id intCoTr_Name varchar (translated name for each Country)CoTr_Active bit--------------------------------------------------------DATA:FOR Language:Id Name Default Mandatory Active1 'English' 1 1 12 'Spanish' 0 1 13 'French' 0 0 1FOR Country:Id ISO Flag Active1 'US' 'us.gif' 12 'FR' 'fr.gif' 13 'DE' 'de.gif' 1FOR CountryTr:Id CId LId Name Active1 1 1 'United States' 12 1 2 'Estados Unidos' 13 1 3 'Etats Units' 14 2 1 'France' 15 2 2 'Francia' 16 2 3 'France' 17 3 1 'Germany' 18 3 2 'Alemania' 19 3 3 'Allemagne' 0As you can see the only non active translation is Germany in French.So, if I call a list of Countries in English, everything would run fine.CountryList @Lang_Id = 1RESULT:Id ISO Name LangId1 'US' 'United States' 12 'FR' 'France' 13 'DE' 'Germany' 1Also if I call for a spanish listing:CountryList @Lang_Id = 2RESULT:Id ISO Name LangId1 'US' 'Estados Unides' 22 'FR' 'Francia' 23 'DE' 'Alemania' 2But if I list them in French, French translation for Germany will miss and default language translation would be brought (English)CountryList @Lang_Id = 3RESULT:Id ISO Name LangId1 'US' 'Etats Units' 32 'FR' 'France' 33 'DE' 'Germany' 1I can't achieve this behavior for the listing Stored.ThanksRegards |
 |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2012-02-28 : 04:34:05
|
Sorry, snowed under, don't know when I'll get a chance to look at it.Why delete the table creation scripts? Now it's harder to run up a testable solution as I have to turn the descriptions into CREATE TABLE and the lists into INSERT statements.--Gail ShawSQL Server MVP |
 |
|
Gudea
Starting Member
18 Posts |
Posted - 2012-02-28 : 07:10:15
|
Sorry I thought it was too pretentious you to create the whole database for me to test.I'll post the script again if useful.Thanks a lot |
 |
|
Gudea
Starting Member
18 Posts |
Posted - 2012-02-28 : 12:25:22
|
I'll post a script to create the database just as I described here.You will see that theese listings bring all countries since they have a translation for the specified language:CountryList @Language_Id = 1 --EnglishCountryList @Language_Id = 2 --SpanishBut when listing in French, Germany is ommited cause it has no translation to that language.CountryList @Language_Id = 3 --FrenchIt is supossed that Germany would be listed also but with its default translation (English) as 'Germany'Thanks a lot/****** Object: ForeignKey [FK_CountryTr_Country] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CountryTr_Country]') AND parent_object_id = OBJECT_ID(N'[dbo].[CountryTr]'))ALTER TABLE [dbo].[CountryTr] DROP CONSTRAINT [FK_CountryTr_Country]GO/****** Object: ForeignKey [FK_CountryTr_Language] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CountryTr_Language]') AND parent_object_id = OBJECT_ID(N'[dbo].[CountryTr]'))ALTER TABLE [dbo].[CountryTr] DROP CONSTRAINT [FK_CountryTr_Language]GO/****** Object: Default [DF_Country_Coun_Active] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.default_constraints WHERE object_id = OBJECT_ID(N'[dbo].[DF_Country_Coun_Active]') AND parent_object_id = OBJECT_ID(N'[dbo].[Country]'))BeginALTER TABLE [dbo].[Country] DROP CONSTRAINT [DF_Country_Coun_Active]EndGO/****** Object: Default [DF_CountryTr_CoTr_Active] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.default_constraints WHERE object_id = OBJECT_ID(N'[dbo].[DF_CountryTr_CoTr_Active]') AND parent_object_id = OBJECT_ID(N'[dbo].[CountryTr]'))BeginALTER TABLE [dbo].[CountryTr] DROP CONSTRAINT [DF_CountryTr_CoTr_Active]EndGO/****** Object: Default [DF_Language_Lang_Default] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.default_constraints WHERE object_id = OBJECT_ID(N'[dbo].[DF_Language_Lang_Default]') AND parent_object_id = OBJECT_ID(N'[dbo].[Language]'))BeginALTER TABLE [dbo].[Language] DROP CONSTRAINT [DF_Language_Lang_Default]EndGO/****** Object: Default [DF_Language_Lang_Mandatory] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.default_constraints WHERE object_id = OBJECT_ID(N'[dbo].[DF_Language_Lang_Mandatory]') AND parent_object_id = OBJECT_ID(N'[dbo].[Language]'))BeginALTER TABLE [dbo].[Language] DROP CONSTRAINT [DF_Language_Lang_Mandatory]EndGO/****** Object: Default [DF_Language_Lang_Active] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.default_constraints WHERE object_id = OBJECT_ID(N'[dbo].[DF_Language_Lang_Active]') AND parent_object_id = OBJECT_ID(N'[dbo].[Language]'))BeginALTER TABLE [dbo].[Language] DROP CONSTRAINT [DF_Language_Lang_Active]EndGO/****** Object: StoredProcedure [dbo].[CountryList] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CountryList]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[CountryList]GO/****** Object: Table [dbo].[CountryTr] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CountryTr]') AND type in (N'U'))DROP TABLE [dbo].[CountryTr]GO/****** Object: Table [dbo].[Language] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Language]') AND type in (N'U'))DROP TABLE [dbo].[Language]GO/****** Object: Table [dbo].[Country] Script Date: 02/28/2012 14:21:02 ******/IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Country]') AND type in (N'U'))DROP TABLE [dbo].[Country]GO/****** Object: Table [dbo].[Country] Script Date: 02/28/2012 14:21:02 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Country]') AND type in (N'U'))BEGINCREATE TABLE [dbo].[Country]( [Coun_Id] [int] NOT NULL, [Coun_ISO] [varchar](50) COLLATE Modern_Spanish_CI_AS NOT NULL, [Coun_Flag] [varchar](50) COLLATE Modern_Spanish_CI_AS NOT NULL, [Coun_Active] [bit] NOT NULL, CONSTRAINT [PK_Country] PRIMARY KEY CLUSTERED ( [Coun_Id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON))ENDGOINSERT [dbo].[Country] ([Coun_Id], [Coun_ISO], [Coun_Flag], [Coun_Active]) VALUES (1, N'US', N'us.gif', 1)INSERT [dbo].[Country] ([Coun_Id], [Coun_ISO], [Coun_Flag], [Coun_Active]) VALUES (2, N'AR', N'ar.gif', 1)INSERT [dbo].[Country] ([Coun_Id], [Coun_ISO], [Coun_Flag], [Coun_Active]) VALUES (3, N'DE', N'de.gif', 1)/****** Object: Table [dbo].[Language] Script Date: 02/28/2012 14:21:02 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Language]') AND type in (N'U'))BEGINCREATE TABLE [dbo].[Language]( [Lang_Id] [int] NOT NULL, [Lang_Name] [varchar](50) COLLATE Modern_Spanish_CI_AS NOT NULL, [Lang_Default] [bit] NOT NULL, [Lang_Mandatory] [bit] NOT NULL, [Lang_Active] [bit] NOT NULL, CONSTRAINT [PK_Language] PRIMARY KEY CLUSTERED ( [Lang_Id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON))ENDGOINSERT [dbo].[Language] ([Lang_Id], [Lang_Name], [Lang_Default], [Lang_Mandatory], [Lang_Active]) VALUES (1, N'English', 1, 1, 1)INSERT [dbo].[Language] ([Lang_Id], [Lang_Name], [Lang_Default], [Lang_Mandatory], [Lang_Active]) VALUES (2, N'Spanish', 0, 0, 1)INSERT [dbo].[Language] ([Lang_Id], [Lang_Name], [Lang_Default], [Lang_Mandatory], [Lang_Active]) VALUES (3, N'French', 0, 0, 1)/****** Object: Table [dbo].[CountryTr] Script Date: 02/28/2012 14:21:02 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CountryTr]') AND type in (N'U'))BEGINCREATE TABLE [dbo].[CountryTr]( [CoTr_Id] [int] NOT NULL, [CoTr_Coun_Id] [int] NOT NULL, [CoTr_Lang_Id] [int] NOT NULL, [CoTr_Name] [varchar](50) COLLATE Modern_Spanish_CI_AS NOT NULL, [CoTr_Active] [bit] NOT NULL, CONSTRAINT [PK_CountryTr] PRIMARY KEY CLUSTERED ( [CoTr_Id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON))ENDGOINSERT [dbo].[CountryTr] ([CoTr_Id], [CoTr_Coun_Id], [CoTr_Lang_Id], [CoTr_Name], [CoTr_Active]) VALUES (1, 1, 1, N'United States', 1)INSERT [dbo].[CountryTr] ([CoTr_Id], [CoTr_Coun_Id], [CoTr_Lang_Id], [CoTr_Name], [CoTr_Active]) VALUES (2, 1, 2, N'Estados Unidos', 1)INSERT [dbo].[CountryTr] ([CoTr_Id], [CoTr_Coun_Id], [CoTr_Lang_Id], [CoTr_Name], [CoTr_Active]) VALUES (3, 1, 3, N'Estats Units', 1)INSERT [dbo].[CountryTr] ([CoTr_Id], [CoTr_Coun_Id], [CoTr_Lang_Id], [CoTr_Name], [CoTr_Active]) VALUES (4, 2, 1, N'Argentine', 1)INSERT [dbo].[CountryTr] ([CoTr_Id], [CoTr_Coun_Id], [CoTr_Lang_Id], [CoTr_Name], [CoTr_Active]) VALUES (5, 2, 2, N'Argentina', 1)INSERT [dbo].[CountryTr] ([CoTr_Id], [CoTr_Coun_Id], [CoTr_Lang_Id], [CoTr_Name], [CoTr_Active]) VALUES (6, 2, 3, N'Argentine', 1)INSERT [dbo].[CountryTr] ([CoTr_Id], [CoTr_Coun_Id], [CoTr_Lang_Id], [CoTr_Name], [CoTr_Active]) VALUES (7, 3, 1, N'Germany', 1)INSERT [dbo].[CountryTr] ([CoTr_Id], [CoTr_Coun_Id], [CoTr_Lang_Id], [CoTr_Name], [CoTr_Active]) VALUES (8, 3, 2, N'Alemania', 1)INSERT [dbo].[CountryTr] ([CoTr_Id], [CoTr_Coun_Id], [CoTr_Lang_Id], [CoTr_Name], [CoTr_Active]) VALUES (9, 3, 3, N'Alemagne', 0)/****** Object: StoredProcedure [dbo].[CountryList] Script Date: 02/28/2012 14:21:02 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CountryList]') AND type in (N'P', N'PC'))BEGINEXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[CountryList] @Language_Id intASBEGIN SET NOCOUNT ON; SELECT DISTINCTc.Coun_Id,c.Coun_ISO,ct.CoTr_Name As Coun_Name,COALESCE(l1.Lang_Id,l2.Lang_Id) AS Lang_IdFROMCountry cLEFT JOIN CountryTr ctON ct.CoTr_Coun_Id = c.Coun_IdLEFT JOIN Language l1ON l1.Lang_Id = ct.CoTr_Lang_IdCROSS JOIN Language l2WHERECOALESCE(l1.Lang_Id,l2.Lang_Id) = @Language_Id ANDCoun_Active = 1ANDCoTr_Active = 1END' ENDGO/****** Object: Default [DF_Country_Coun_Active] Script Date: 02/28/2012 14:21:02 ******/IF Not EXISTS (SELECT * FROM sys.default_constraints WHERE object_id = OBJECT_ID(N'[dbo].[DF_Country_Coun_Active]') AND parent_object_id = OBJECT_ID(N'[dbo].[Country]'))BeginALTER TABLE [dbo].[Country] ADD CONSTRAINT [DF_Country_Coun_Active] DEFAULT ((1)) FOR [Coun_Active]EndGO/****** Object: Default [DF_CountryTr_CoTr_Active] Script Date: 02/28/2012 14:21:02 ******/IF Not EXISTS (SELECT * FROM sys.default_constraints WHERE object_id = OBJECT_ID(N'[dbo].[DF_CountryTr_CoTr_Active]') AND parent_object_id = OBJECT_ID(N'[dbo].[CountryTr]'))BeginALTER TABLE [dbo].[CountryTr] ADD CONSTRAINT [DF_CountryTr_CoTr_Active] DEFAULT ((1)) FOR [CoTr_Active]EndGO/****** Object: Default [DF_Language_Lang_Default] Script Date: 02/28/2012 14:21:02 ******/IF Not EXISTS (SELECT * FROM sys.default_constraints WHERE object_id = OBJECT_ID(N'[dbo].[DF_Language_Lang_Default]') AND parent_object_id = OBJECT_ID(N'[dbo].[Language]'))BeginALTER TABLE [dbo].[Language] ADD CONSTRAINT [DF_Language_Lang_Default] DEFAULT ((0)) FOR [Lang_Default]EndGO/****** Object: Default [DF_Language_Lang_Mandatory] Script Date: 02/28/2012 14:21:02 ******/IF Not EXISTS (SELECT * FROM sys.default_constraints WHERE object_id = OBJECT_ID(N'[dbo].[DF_Language_Lang_Mandatory]') AND parent_object_id = OBJECT_ID(N'[dbo].[Language]'))BeginALTER TABLE [dbo].[Language] ADD CONSTRAINT [DF_Language_Lang_Mandatory] DEFAULT ((0)) FOR [Lang_Mandatory]EndGO/****** Object: Default [DF_Language_Lang_Active] Script Date: 02/28/2012 14:21:02 ******/IF Not EXISTS (SELECT * FROM sys.default_constraints WHERE object_id = OBJECT_ID(N'[dbo].[DF_Language_Lang_Active]') AND parent_object_id = OBJECT_ID(N'[dbo].[Language]'))BeginALTER TABLE [dbo].[Language] ADD CONSTRAINT [DF_Language_Lang_Active] DEFAULT ((1)) FOR [Lang_Active]EndGO/****** Object: ForeignKey [FK_CountryTr_Country] Script Date: 02/28/2012 14:21:02 ******/IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CountryTr_Country]') AND parent_object_id = OBJECT_ID(N'[dbo].[CountryTr]'))ALTER TABLE [dbo].[CountryTr] WITH CHECK ADD CONSTRAINT [FK_CountryTr_Country] FOREIGN KEY([CoTr_Coun_Id])REFERENCES [dbo].[Country] ([Coun_Id])GOALTER TABLE [dbo].[CountryTr] CHECK CONSTRAINT [FK_CountryTr_Country]GO/****** Object: ForeignKey [FK_CountryTr_Language] Script Date: 02/28/2012 14:21:02 ******/IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_CountryTr_Language]') AND parent_object_id = OBJECT_ID(N'[dbo].[CountryTr]'))ALTER TABLE [dbo].[CountryTr] WITH CHECK ADD CONSTRAINT [FK_CountryTr_Language] FOREIGN KEY([CoTr_Lang_Id])REFERENCES [dbo].[Language] ([Lang_Id])GOALTER TABLE [dbo].[CountryTr] CHECK CONSTRAINT [FK_CountryTr_Language]GO |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-28 : 15:38:14
|
[code]CREATE PROCEDURE dbo.CountryList@Language_Id intASSELECT m.Coun_Id,m.ISO,COALESCE(ct.Name,df.Name) AS Name,COALESCE(ct.LangID,df.LangID) AS LangIDFROM(SELECTc.Coun_Id,c.ISO,l.Lang_IdFROM Country cCROSS JOIN Language lWHERE l.LandID=@IDvalue)mLEFT JOIN CountryTr ctON ct.CoTr_Coun_Id = m.Coun_IdAND ct.CoTr_Lang_Id = m.Lang_IdAND ct.Active=1CROSS JOIN (SELECT l1.LangId,ct1.Name FROM Language l1 INNER JOIN CountryTr ct1 ON ct1.CoTr_Lang_Id = l1.Lang_Id WHERE l1.Default=1 )df[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
Gudea
Starting Member
18 Posts |
Posted - 2012-02-28 : 18:49:42
|
Thanks visakh for all this effort!The stored as it is does not compile. Some column names are different from database structure and even parameter name differs. As I understand you may have meant something like this:ALTER PROCEDURE dbo.CountryList@Language_Id intASSELECT m.Coun_Id,m.Coun_ISO ,COALESCE(ct.CoTr_Name,df.CoTr_Name) AS Coun_Name,COALESCE(ct.CoTr_Lang_Id,df.CoTr_Lang_Id) AS [Lang_ID]FROM (SELECT c.Coun_Id, c.Coun_ISO, l.Lang_Id FROM Country c CROSS JOIN [Language] l WHERE l.Lang_Id = @Language_Id )mLEFT JOIN CountryTr ctON ct.CoTr_Coun_Id = m.Coun_IdAND ct.CoTr_Lang_Id = m.Lang_IdAND ct.CoTr_Active =1CROSS JOIN (SELECT l1.Lang_Id ,ct1.CoTr_Name, ct1.CoTr_Lang_Id FROM [Language] l1 INNER JOIN CountryTr ct1 ON ct1.CoTr_Lang_Id = l1.Lang_Id WHERE l1.Lang_Default =1 )dfThis one compiles, but doesn´t bring the right results.English listing [CountryList 1] brings:1 US United States 11 US United States 11 US United States 12 AR Argentine 12 AR Argentine 12 AR Argentine 13 DE Germany 13 DE Germany 13 DE Germany 1Where expected:1 US United States 12 AR Argentine 13 DE Germany 1It seems that a DISTINCT would help, and it does, but...When listing in French (missing Germany´s translation)CountryList 3The results are (with DISTINCT):1 US Estats Units 32 AR Argentine 33 DE Argentine 13 DE Germany 13 DE United States 1Where expected:1 US Estats Units 32 AR Argentine 33 DE Germany 1It is pretty close!! but it seems that when a translation is missing it brings all translations in default language for all countries mixed with the same ISO and Id of the non translated Country.May be I have corrected wrong the stored.ThanksRegards |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-28 : 18:57:18
|
[code]ALTER PROCEDURE dbo.CountryList@Language_Id intASSELECT m.Coun_Id,m.Coun_ISO ,COALESCE(ct.CoTr_Name,df.CoTr_Name) AS Coun_Name,COALESCE(ct.CoTr_Lang_Id,df.CoTr_Lang_Id) AS [Lang_ID]FROM(SELECTc.Coun_Id, c.Coun_ISO,l.Lang_IdFROM Country cCROSS JOIN [Language] lWHERE l.Lang_Id = @Language_Id )mLEFT JOIN CountryTr ctON ct.CoTr_Coun_Id = m.Coun_IdAND ct.CoTr_Lang_Id = m.Lang_IdAND ct.CoTr_Active =1CROSS APPLY(SELECT l1.Lang_Id ,ct1.CoTr_Name, ct1.CoTr_Lang_Id FROM [Language] l1INNER JOIN CountryTr ct1ON ct1.CoTr_Lang_Id = l1.Lang_IdWHERE l1.Lang_Default =1AND ctl.CoTr_Coun_Id = m.Coun_Id)df[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
Gudea
Starting Member
18 Posts |
Posted - 2012-02-29 : 09:21:16
|
Great!It worked!Thanks a lot to everyone.Regards |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-29 : 12:09:50
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|