Format cost into local currency format SQL - sql-server-2008

I need to converts costs into Vietnam and Indonesia.
Is there any way that we could format the value dynamically using the culture of the country currency?
Example:
7859948,84 to 7,859,948.84
Thanks in advance

Format your data at the presentation layer, not in the database. Store it as the appropriate data type in the database (probably money), then format it using the correct culture in whatever application you're using to present to the user, using the user's preferred culture settings.
if you must do it in the database:
For SQL Server 2008R2 and earlier, you'll have to use a CLR function. See this SO answer
It can be done in T-SQL as of SQL Server 2012 using FORMAT() and the vi-VN culture string.
select 7859948.84, format(7859948.84,'N','vi-VN');
Yields 7.859.948,84 which, according to MS's culture settings, is the correct format for Vietnamese numbers.
But even though you can do it in newer versions of SQL Server, it should still be done in the presentation layer.

Related

How can I change month name in MySQL

I want to make my database language Turkish. I want to take month name Turkish but its English.
I tried this, but It doesn't work for me. Nothing happens.
Suggestion: You don't need to store turkish language data in database. Rather, have it in English in your database, retrieve the necessary data and perform the localization/globalization conversion in your application end while displaying the data to your end user.
Again, going by the documentation you need to set the lc_time_names global variable to tr-TR to have turkish language effict
You can use momentjs which is a javascript language for date and time handling. It comes with another package called moment.locale to format your dates in other languages:
moment.locale("tr-TR").format('LLL');
Per #Nashenas:
With momentjs 2.8+, do the following:
moment.locale("tr-TR").format('LLL');
For current version of momentjs (2016)
moment.locale("tr-TR");
just returns "de" and no moment-object.
To get a formated date you need:
moment().locale("tr-TR").format('LLL');
More info here.
Create a plunker
https://plnkr.co/edit/ffT9JxQcVuQaHKGzYQZS?p=preview

Is there any similar function as of FORMAT in SQL Server 2008 or 2010

AS MSDN :
FORMAT Returns a value formatted with the specified format and
optional culture in SQL Server 2012. Use the FORMAT function for
locale-aware formatting of date/time and number values as strings.
Is this or any similar function available in 2008 or R2 or 2010 for formatting purpose?
Update:
I don't know too. But I heard Microsoft released some SQL Version code-named 'Denali' in year 2010 as Sql 2010 or 2011
There is no explicit FORMAT function, but if you are converting a datatype to a string (such as date etc) the CONVERT function supports different formats that can be applied by specifying the correct code.
The codes are detailed here:
CAST and CONVERT
e.g. if you wanted to format a datetime as a string with the format "YYYY-MM-DD HH:MI:SS", you could use the following:
SELECT CONVERT(VARCHAR(19), GETDATE(), 120)
Where the code 120 is the style.
It works for more than just dates too, I've used it with varbinary and XML data too.

SQL Server (T-SQL) datetime conversion

A silly question maybe but I wanted clarification. I've created a script that has a date parameter like so:
DECLARE #dateparam as datetime
SET #dateparam = '01-01-2013 00:00:00'
This looks like it is working when I test it even if the date string is not in "correct" format yyyy-MM-dd hh:mm:ss. I changed my computer regional settings to English and the script still did what it was supposed to do.
Is this because of SQL Server 2008 R2 that I have in my computer that it knows how to convert the date or can I ran into trouble with using a dateformat like I have used?
Converting 01-01-2013 won't expose issues such as which 01 is the month, and which is the day.
It's not a safe format.
The safe formats (for converting to datetime, rather than to datetime2) are:
YYYYMMDD 20121201
YYYY-MM-DD'T'hh:mm:ss 2012-12-01T10:43:29
YYYY-MM-DD'T'hh:mm:ss.mil 2012-12-01T10:43:29.337
Stick to those and only those. (The examples all represent the 1st December 2012)
Or, better yet, don't treat dates as strings at all, if you can avoid it. If you're, for example, calling SQL Server from .NET code, keep that dates as DateTimes in your code, and let ADO.NET and SQL Server deal with any required translations to make them become datetimes - without translating them to and from strings.
You're making an implicit conversion from something that looks like a date, but inf fact is a string ( '01-01-2013 00:00:00'). Rather than trusting on SQL Server to make the correct guess in what format the string is in, you should make the conversion explicit by specifying the format.
This can be done by using CONVERT (not CAST) and specify a 'style'. The different styles are listed here: http://msdn.microsoft.com/en-us/library/ms187928.aspx.

Delphi / MySql : timestamp in DB aware components

Delphi does not use *nix timestamps. In other apps I have converted to *nix before storing in MySql and reversing that when retrieving.
Now I would like to try using DB aware components for the first time. How will it work for tiemstamps? Should I (can I) store in Delphi tiemstamp format? Or shoudl I convert to *nix before storing?
For normal use your do not need to do anything.
I had used Delphi / MySQL for many year and all data access components I had used (dbexpress / zeros / MyDAC) do the conversion automatically. In case I need to manually specify the timestamp value, I just provide the text format ("yyyy/mm/dd hh:nn:ss")

Get correct output from UTF-8 stored in VarChar using Entity Framework or Linq2SQL?

Borland StarTeam seems to store its data as UTF-8 encoded data in VarChar fields. I have an ASP.NET MVC site that returns some custom HTML reports using the StarTeam database, and I would like to find a better solution for getting the correct data, for a rewrite with MVC2.
I tried a few things with Encoding GetBytes and GetString, but I couldn't get it to work (we use mostly Delphi at work); then I figured out a T-SQL function to return a NVarChar from UTF-8 stored in a VarChar, and created new SQL views which return the data as NVarChar, but it's slow.
The actual problem appears like this: “description†instead of “description”, in both SSMS and in a webpage when using Linq2SQL
Is there a way to get the proper data out of these fields using Entity Framework or Linq2SQL?
Well, once you get the data out, you could always try this:
Encoding.UTF8.GetString(Encoding.Default.GetBytes(item.Description))
assuming the field is encoded in the system ANSI page. You might have to create the right encoding with Encoding.GetEncoding() if for some reason it isn't (looked up from DB type, for example).