I have a sql query which which will check a table called USER_PROFILE_ENTRY for STRING_VAL under a specific where clause as given below and set it for extension_locale
Select extension_locale = (select STRING_VAL from USER_PROFILE_ENTRY
where PROFILE_KEY = 'Culture' and ottr.USER_ID = USER_PROFILE_ENTRY.USER_ID)
from USER_DATA ottr where USER_TYPE = 'U'
FOR JSON PATH
the ottr.USER_ID in the where clause is from a table called USER_DATA so when you run below query and if there is no value which satifies this condition -> ottr.USER_ID = USER_PROFILE_ENTRY.USER_ID then nothing will be returned
select STRING_VAL from USER_PROFILE_ENTRY
where PROFILE_KEY = 'Culture' and ottr.USER_ID = USER_PROFILE_ENTRY.USER_ID
But what I want is, if there is no value for above where condition, it should print extension_timezone = "" instead of not printing anything at all.
Below is output of above query :
[
{},
{
"extension_locale": "en-US"
},
{},
{
"extension_locale": "en-US"
},
{
"extension_locale": "en-GB"
},
{},
{},
{
"extension_locale": "en-GB"
},
{
"extension_locale": "en-GB"
},
{
"extension_locale": "en-GB"
}
]
So if you see the output, there are many {} (empty blocks) it means there was no satisfying where clause hence and empty output but what I want is like this :
[
{
"extension_locale": ""
},
{
"extension_locale": "en-US"
},
{
"extension_locale": "en-US"
},
{
"extension_locale": "en-GB"
},
{
"extension_locale": ""
},
{
"extension_locale": ""
},
{
"extension_locale": "en-GB"
},
{
"extension_locale": "en-GB"
},
{
"extension_locale": "en-GB"
}
]
sql-server-2008tag seems to be wrong. What is your actual SQL Server version?