nvarchar

Conversion error when converting 'nvarchar' to 'datetime' in sql server

余生颓废 提交于 2019-12-08 11:35:34
问题 I have this code : DECLARE @StartDate nvarchar SET @StartDate='22/10/2014' SELECT CAST (@StartDate as datetime) And it gives me this error: Conversion failed when converting date and/or time from character string. Can anyone suggest a better way/at least no error way to do this. 回答1: To convert the string which represents to date in format dd/mm/yyyy you can use this: DECLARE @StartDate nvarchar(10) SET @StartDate='22/10/2014' SELECT CONVERT(datetime, @StartDate, 103) Declaring varchar means

SQL Server : when to use collation and nvarchar

爱⌒轻易说出口 提交于 2019-12-08 05:25:01
问题 Currently my column datatype is varchar in my SQL Server table. I want to store both English and Chinese characters in my column. What steps do I have to follow to use collation, or do I have to change the datatype to NVARCHAR and insert with N' as unicode? If I have to use collation what collation I should use. Please help me in this 回答1: You are mixing two concepts: data type and encoding VARCHAR stores your data in chunks of 8 bit. basic characters are one chunk. But sometimes there is one

Nvarchar perform better than varchar?

99封情书 提交于 2019-12-07 16:47:11
问题 I am really surprisde to see that in my MS SQL table, I am defining a field varchar and doing group by with another table's field. When I do the same thing with the column as nvarchar it is 3 second faster than varchar when, theoretically, varchar should be faster because of 1 byte char. Can anyone explain me why nvarchar is faster in this instance? Thanks in advance. 回答1: Operating systems use Unicode internally. I think that makes nvarchar faster since it does not need any converting. 来源:

Inserting special characters (greater/less than or equal symbol) into SQL Server database

你。 提交于 2019-12-07 01:37:21
问题 I am trying to insert ≤ and ≥ into a symbol table where the column is of type nvarchar . Is this possible or are these symbols not allowed in SQL Server? 回答1: To make it work, prefix the string with N create table symboltable ( val nvarchar(10) ) insert into symboltable values(N'≥') select * from symboltable Further Reading : You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server Why do some SQL strings have an 'N' prefix? 回答2: To add to

Nvarchar perform better than varchar?

ぃ、小莉子 提交于 2019-12-06 04:05:47
I am really surprisde to see that in my MS SQL table, I am defining a field varchar and doing group by with another table's field. When I do the same thing with the column as nvarchar it is 3 second faster than varchar when, theoretically, varchar should be faster because of 1 byte char. Can anyone explain me why nvarchar is faster in this instance? Thanks in advance. Operating systems use Unicode internally. I think that makes nvarchar faster since it does not need any converting. 来源: https://stackoverflow.com/questions/6250728/nvarchar-perform-better-than-varchar

How BIG do you make your Nvarchar()

别来无恙 提交于 2019-12-05 18:52:42
When designing a database, what decisions do you consider when deciding how big your nvarchar should be. If i was to make an address table my gut reaction would be for address line 1 to be nvarchar(255) like an old access database. I have found using this has got me in bother with the old 'The string would be truncated'. I know that this can be prevented by limiting the input box but if a user really has a address line one that is over 255 this should be allowed. How big should I make my nvarchar(????) My recommendation: make them just as big as you REALLY need them. E.g. for a zip code column

How to decode nvarchar to text (SQL Server 2008 R2)?

…衆ロ難τιáo~ 提交于 2019-12-05 05:50:15
I have a SQL Server 2008 R2 table with nvarchar(4000) field. Data that stores this table look like '696D616765206D61726B65643A5472' or '303131' ("011") . I see that each char is encoding to hex. How can I read those data from table? I don't want write decoding function, I mean that simpler way exists. P.S. Sorry for my English. SQL Server 2008 actually has a built-in hex-encoding and decoding feature! Sample (note the third parameter with value "1" when converting your string to VarBinary): DECLARE @ProblemString VarChar(4000) = '54657374' SELECT Convert(VarChar, Convert(VarBinary, '0x' +

Inserting special characters (greater/less than or equal symbol) into SQL Server database

空扰寡人 提交于 2019-12-05 05:02:55
I am trying to insert ≤ and ≥ into a symbol table where the column is of type nvarchar . Is this possible or are these symbols not allowed in SQL Server? Gonzalo.- To make it work, prefix the string with N create table symboltable ( val nvarchar(10) ) insert into symboltable values(N'≥') select * from symboltable Further Reading : You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server Why do some SQL strings have an 'N' prefix? To add to gonzalo's answer, both the string literal and the field need to support unicode characters . String

Determining Nvarchar length

Deadly 提交于 2019-12-05 02:40:52
I've read all about varchar versus nvarchar. But I didn't see an answer to what I think is a simple question. How do you determine the length of your nvarchar column? For varchar it's very simple: my Description, for example, can have 100 characters, so I define varchar(100). Now I'm told we need to internationalize and support any language. Does this mean I need to change my Description column to nvarchar(200), i.e. simply double the length? (And I'm ignoring all the other issues that are involved with internationalization for the moment.) Is it that simple? Generally it is the same as for

Syntax for linq query to List<string>

会有一股神秘感。 提交于 2019-12-05 02:23:58
I am trying to do something like this... public static List<string> GetAttachmentKeyList() { DataClassesDataContext dc = new DataClassesDataContext(); List<string> list = from a in dc.Attachments select a.Att_Key.ToString().ToList(); return list; } Visual Studio is saying... Cannot implicitly convert type 'System.Linq.IQueryable>' to 'System.Collections.Generic.List'. An explicit conversion exists (are you missing a cast?) What is the proper syntax??? Give this a try public static List<string> GetAttachmentKeyList() { DataClassesDataContext dc = new DataClassesDataContext(); List<string> list