I am in the UK. I have a Windows 2008 server in Germany with SQL Server 2008 R2 Express installed on it. The regional settings for Windows are set to UK. SQL Server language is set to English. When I run
sp_helplanguage ##LANGUAGE
it shows that it is set to
us_english
I have numerous tables in the database that have float datatypes in them. When I use SSMS to change one of the float values, if I type in
1234.1234
firstly it displays as
1234,1234
then when I click off the row to save it, it displays as
12341234
The ASP.NET application, that is being served the data via a stored procedure and being put into a double (VB.NET), does a
String.Format("{0:#0.0000}", dMyDouble)
This renders as
12341234,0000
Needless to say, on my local server (all UK based) all database entered numbers display as I would expect (1234.1234) and .NET formats them as I would expect (1234.1234). I am aware that my European friends use a different notation to us in the UK, but I need the UK format to be output - and more importantly the float in the database!
The fact that .NET is not formatting correctly, I imagine is purely to do with the fact that the number is not storing the accuracy.
I have also played around a bit by using a decimal column (18, 4) and I get a similar outcome. As I type 1234.1234 using the point (.) it replaces with a comma (,). When the row is saved, it saves as
12341234.0000
You must set the LANGUAGE on your session to the desired setting.
But, despite the fact that you did not show any C# code, the fact that you're seeing formatting issues it means you're passing the values as text in SQL Commands. You should be using #variables instead. This would have the side benefit of avoiding SQL injection issues.
Related
I am working with a SQL Server 2008 database on a Windows 2008 Server. Anytime I try to store an emoji in my table it converts it to a weird looking box. When I try to store the same emoji in SQL Server 2012 it stores the emoji fine. Is it not possible to store emojis correctly in SQL Server 2008? I really cannot update at this point so that would not be an option.
What we know based on details from the question and comments on the question:
Column is NVARCHAR
Value is inserted from VB.NET app via stored procedure
App hitting SQL Server 2008 (running on Windows 2008 Server) stores emoji character but "converts it to a weird looking box"
Same app code hitting SQL Server 2012 stores the same emoji character just fine
What we do not know:
How is the character being retrieved in order to determine whether or not it was stored correctly?
Are you viewing it in the app or in SSMS?
If in SSMS, are you connecting to SQL Server 2008 and 2012 using the same SSMS running on the same machine? Or are you using the version of SSMS that came with each version of SQL Server (hence they are not the same program, even if on the same machine)?
Based on the above:
Most likely this is a font issue. I say this due to:
If it were an issue of not supporting Unicode, then you would be seeing two question marks ?? (one for each surrogate character) instead of a single square box.
Emojis are nothing special. They are merely supplementary characters. And there are currently (as of Unicode v 12.0) 72,457 supplementary characters defined (and slots for another 976,119).
Supplementary Characters (emojis or otherwise) can be stored in NCHAR, NVARCHAR, and NTEXT columns without a problem, and without regard to the collation of the column or the current database.
To test this, I executed the following in a database having a default collation of SQL_Latin1_General_CP1_CI_AS, so there is definitely no "supplementary character support" there.
SELECT NCHAR(0xD83D) + NCHAR(0xDE31) AS [ScreamingFace],
NCHAR(0xD83D) + NCHAR(0xDDFA) AS [WorldMap],
NCHAR(0xD83D) + NCHAR(0xDF08) AS [Alchemical Symbol for Aqua Vitae];
It returns:
ScreamingFace WorldMap Alchemical Symbol for Aqua Vitae
😱 🗺 🜈
I see different things in different areas, all due to font differences. The chart below indicates what I am seeing:
LOCATION FONT Screaming World Alchemical Symbol
Face Map for Aqua Vitae
------------ ------------ ---------- ------ ----------------------------
Text Editor Consolas Yes Yes Square box w/ question mark
Grid Results Code2003 Yes Yes Yes
Text Results Courier New Yes Yes Empty square box
Most likely you were using two different versions of SSMS, or at least SSMS on two different computers. In either case, you probably had different fonts mapped to the Grid Results, or were even using Grid Results on one and Text Results on the other.
In the end, if you want to know if data was stored correctly, you need to check the bytes that were stored. To do this, simply convert the string column to VARBINARY(MAX):
SELECT CONVERT(VARBINARY(MAX), string_column)
FROM schema.table;
And compare those results between the 2008 and 2012 systems. More than likely they are (or "were" given that this was almost 2.5 years ago) the same.
For more info on what characters can actually be stored in the various string datatypes in SQL Server (from SQL Server 7.0 through at least SQL Server 2019), please read the following post of mine:
How Many Bytes Per Character in SQL Server: a Completely Complete Guide
I have a MS Access 2010 front end / SQL Server 2012 back end database, with a number of date fields in different tables. Sometimes I need to store the time, so I have used data types datetime or smalldatetime. However certain fields only need to store the date, so I used data type Date.
My problem is that in MS Access, my ODBC-linked table shows the Date data type fields as Text. This is then leading to problems with some dates being stored in the yyyy-dd-mm format and others in the yyyy-mm-dd format.
Is this a bug? Do I need to use smalldatetime?
Thanks for any assistance,
Jim
Had the same issue myself linking Access 2007 and SQL Server 2008.
See this question, if you look at Albert D. Kallal's comment to the first answer, it tells us that the problem is with an outdated driver connecting the front end to the back end.
If you aren't able to choose an up-to-date driver (and bear in mind that even if you can, other users of your database on different client machines may not be able to) the workaround is to use datetime data type in every case.
Just to expound on the comment given by #BiigJiim I actually had the Native client 11.0 driver already installed but as I was creating DSN-Less table connections I had to change my connection string formally to: Driver={SQL Server Native Client 11.0};
Also as an additional note, I do not believe the Date and DateTime2 data types are recommended for Microsoft Access integration. If memory serves me correctly it recommends either DateTime and SmallDateTime. I get not needing the Time in a lot of circumstances, but you can easily format it via the front end... especially within Access.
Looking at various installations of SQL Server, sometimes the 4th column returned by xp_msver will sometimes be nvarchar and sometimes it will be varchar. This appears to have no bearing on the version of SQL Server, since I see some copies of SQL Server 2000 up to 2012 return varchar, while others return nvarchar. This also does not seem to have a bearing on Windows version or bitness.
Why does this happen? and is there a way to either configure the output or know what data type will be used beforehand?
Edit: I am using Visual FoxPro to query this information, which has a number of issues dealing with unicode. So, I need to know how to handle the data and convert it to ANSI/single byte encoding - if it isn't already. I understand the limitations of ANSI/single byte, but the loss of data is considered acceptable here.
sqlexec(connhandle, "exec xp_msver")
If ADO were in the picture, I would just use the data type properties inherit in RecordSets, but i am limited to FoxPro and its own cursor functionality. When pulled into FoxPro, the Character_Value column - the 4th column in question here - is considered a MEMO data type, which is a fancy way of saying a string (of some kind or even binary data) possibly longer than 255 characters. It is really a catchall for long strings and any data types that FoxPro cannot handle, which is extremely unhelpful in this case.
There is a Microsoft KB article that explicitly uses xp_msver from FoxPro and states that SQL Server 7.0 and greater always returns Unicode for the stored procedure, but this is not always the case. Also, since xp_msver it is a stored procedure sp_help and sp_columns aren't of any use here.
In all honesty, I would prefer using SERVERPROPERTY(), but it is not supported in SQL Server 7.0, which is a requirement. I would prefer not to overcomplicate the code by having different queries for different versions of SQL Server. Also, using ##version is not a good option, since it would require parsing the text, would be prone to bugs, and doesn't provide all the information I need.
I'm currently porting a Access 2003 app to use a SQL Server 2005 back-end, and I'm having trouble with the datetime representations.
As I understand it, the default Access behavior is to use the datetime format defined on the local machine's regional settings, as do SQL-Server. Is there a way to force Access to use another default format (other than those available in the "Format" property dropdown list), something like Format = "dd/mm/yyyy"?
My problem is that a good many forms in the app have sub-forms whose data is linked to the parent via relation implying datetime and numeric values (terrible design, I know.)
Now, when retrieving the data, the date will print ok, using a yyyy/mm/dd hh:mm:ss format, but I cannot make new entries, or inserts from the forms as SQL server will complain that the text-data overflowed the capacity for a datetime, or that the engine cannot find the parent record.
I'm using a file-based DSN to connect to the backend.
Thanks for any insight in the matter,
Pascal
Dates are stored in MS Access as numbers. You can set custom formats for controls, such as dd/mm/yyyy, but it nearly always means a deeper problem.
More info: http://office.microsoft.com/en-ie/access-help/format-property-date-time-data-type-HA001232739.aspx
I have a backup of an SQL Server DB in .bak format which I've successfully managed to restore to a local instance of SQL Server Express. I now want to export both the structure and data in a format that MySQL will accept. The tools that I use for MySQL management typically allow me to import/export .sql files, but unfortunately Microsoft didn't see fit to make my life this easy!
I can't believe I'm the first to run into this, but Google hasn't been a great deal of help. Has anybody managed this before?
There will be 2 issues:
1) Datatypes. There isn't always a direct analog between an MS SQL type and a MySQL type. For example, MySQL handles timestamps very differently and has the cut-off for when you need to switch between varchar(n) and varchar(max)/text at a different value of n. There are also some small differences in the numeric types.
2) Query syntax. There are a few differences in the query syntax that, again, don't always have a 1:1 analog replacement. The one that comes to the top of my mind is SELECT TOP N * FROM T in MS SQL becomes SELECT * FROM T LIMIT N in MySQL (MySQL makes paging loads easier).