SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Fetching default record for multiple language
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

keyursoni85
Posting Yak Master

India
233 Posts

Posted - 05/16/2013 :  06:54:06  Show Profile  Reply with Quote
Hi,

I have table with multiple language records in it. And default language will be english.

I have list of records of table for single language e.g. dutch.
For each row, if name is null or empty for dutch then that name should return with default language of english.

May I need to loop cursor to check this each row?

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/16/2013 :  06:56:12  Show Profile  Reply with Quote
Is language stored as a field inside table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

keyursoni85
Posting Yak Master

India
233 Posts

Posted - 05/16/2013 :  06:59:38  Show Profile  Reply with Quote
Yes,


CREATE TABLE #names (ids int, names varchar(44), langcode varchar(10))
insert into #names values 
(1, 'en1', 'en'), (1, 'dt1', 'dt'), (1, '', 'gb'),
(2, 'en2', 'en'), (2, 'dt2', 'dt'), (2, 'gb2', 'gb')

select * from #names 
drop table #names 
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/16/2013 :  07:26:41  Show Profile  Reply with Quote
how will you determine which code corresponds to which language? is there a master table for that? Or does code always represent standard language codes available in sys.languages view?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

keyursoni85
Posting Yak Master

India
233 Posts

Posted - 05/16/2013 :  07:39:21  Show Profile  Reply with Quote
I will pass language code in procedure. determined by country where site is opened.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/16/2013 :  07:46:45  Show Profile  Reply with Quote
sorry you missed my point.My question was reg. how to find language details for records within table. There's no language field. If you want to determine language you need to have a field which stores language values in addition to codes which is there now.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

keyursoni85
Posting Yak Master

India
233 Posts

Posted - 05/16/2013 :  08:01:53  Show Profile  Reply with Quote
there is already field/column added in given example script.

langcode varchar(10))

That column holds language code and from application I will pass code and fetch records.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/16/2013 :  08:08:02  Show Profile  Reply with Quote
so is it always name for passed languagecode or return name for english?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

keyursoni85
Posting Yak Master

India
233 Posts

Posted - 05/16/2013 :  08:16:52  Show Profile  Reply with Quote
Yes, english is default one.

As per given table. You can see multiple language names entered. If I pass dutch language code and if I found 15 records then for each record if name null or empty then english name will returned.
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 05/16/2013 :  16:08:39  Show Profile  Reply with Quote
Here is one way:
select 
	a.ids,
	coalesce(nullif(a.names, ''), English.names) as names
from 
	#names as a
inner join
	#names as English
	on a.ids = English.ids
	and English.langcode = 'en'
	and a.langcode = 'gb'
Go to Top of Page

keyursoni85
Posting Yak Master

India
233 Posts

Posted - 05/17/2013 :  02:08:48  Show Profile  Reply with Quote
Yes, Thanks.. :)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000