Quantcast
Channel: Active questions tagged cte - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 216

How to get text for default language

$
0
0

I have so tables:enter image description here

and so data at Language table:

enter image description here

and so data at Text table:enter image description here

I have to return text for requested language if it exists and text for default language if it does not exist. Is it possible to do that in one query (no while, please)?

Code:

DECLARE @CommentId  bigint = 1--DECLARE @LanguageCode  nvarchar(2) = 'en' -- "english text" returnsDECLARE @LanguageCode  nvarchar(2) = 'ua'   -- nothing at this momentSELECT     t.CommentId    ,t.TextId    ,t.[Text]    ,t.LanguageId    ,RequestedLanguageId = @LanguageCodeFROM dbo.common_Text t     INNER JOIN dbo.common_LanguageType l         ON t.LanguageId = l.LanguageIdWHERE l.Code = @LanguageCode     AND t.CommentId = @CommentId

Thank you.

ADDED:

If code requests a text in 'ua' (ukrainian) and this is no any text for this language, so it is going to search text for russian. if found - ok, if don't it will look for a text for english. List of languages can vary.


Viewing all articles
Browse latest Browse all 216

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>