nvarchar

Does `sp_executesql` really accepts the `nvarchar(max)` argument?

假如想象 提交于 2019-12-10 15:34:35
问题 Summary: The EXEC sp_executesql @code fails for the content longer than 4000 in the @code , but the @code is not truncated to 4000 unicode characters. I am observing the problem on SQL Server 2014 Developer Edition. More details: my SQL installation script defines some code dynamically because it should modify the code so that it reflects the environment (only once, during the installation). Let the following @datasource variable captures results for the specific environment: DECLARE

SQL Server 2008 Nvarchar(Max) concatenation - Truncation issue

有些话、适合烂在心里 提交于 2019-12-10 15:23:15
问题 Can someone please explain why this is happening on SQL Server 2008: declare @sql Nvarchar(max); set @sql =N''; select @sql = @sql +replicate('a',4000) + replicate('b', 6000); select len(@sql) Returns: 8000 Multiple sites suggest that as long as first variable is of type NVARCHAR(MAX), truncation should not occur, but it still does. 回答1: Because 'a' and 'b' are not of type NVARCHAR(MAX) Like this, it should work: declare @sql Nvarchar(max), @a nvarchar(max), @b nvarchar(max); select @sql =N''

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

我是研究僧i 提交于 2019-12-10 04:07:54
问题 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. 回答1: 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

Determining Nvarchar length

情到浓时终转凉″ 提交于 2019-12-10 02:33:49
问题 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

Should I be using JDBC getNString() instead of getString()?

半世苍凉 提交于 2019-12-10 02:01:00
问题 We are building a Java application backed by an Oracle database that we access using JDBC (drivers ojdbc6.jar and orai18n.jar ). The database schema stores text columns primarily using the NVARCHAR2 data type. The JDBC documentation for the JDBC ResultSet says that getNString() is particularly intended for use with the NCHAR, NVARCHAR etc. data types, but at the moment we are only using getString() . This seems to work fine, so I am wondering why I should use getNString() rather than

Syntax for linq query to List<string>

主宰稳场 提交于 2019-12-10 01:20:59
问题 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??? 回答1: Give this a try public static List

SQL Server中nvarchar和varchar的区别

浪子不回头ぞ 提交于 2019-12-09 19:07:19
1、varchar(n)   长度为 n 个字节的可变长度且非 Unicode 的字符数据,n 必须是一个介于 1 和 8,000 之间的数值,存储大小为输入数据的字节的实际长度,而不是 n 个字节,所输入的数据字符长度可以为零。 2、nvarchar(n)   包含 n 个字符的可变长度 Unicode 字符数据,n 的值必须介于 1 与 4,000 之间,字节的存储大小是所输入字符个数的两倍,所输入的数据字符长度可以为零。 3、两种数据类型的区别 首先,varchar和nvarchar都能存储汉字,区别在于:一个汉字占varchar(2),只占nvarchar(1),而字母只占varchar(1),那么在数据库字段求长度的时候,用varchar就不一定知道它确切有几个字符,如果用nvarchar,汉字也是nvarchar(1),字母也是nvarchar(1),那么很容易知道字段的长度了。   其次,varchar的检索快于nvarchar,varchar在SQL Server中是采用单字节来存储数据的,nvarchar是使用Unicode来存储数据的,中文字符存储到SQL Server中会保存为两个字节(一般采用Unicode编码),英文字符保存到数据库中,如果字段的类型为varchar,则只会占用一个字节,而如果字段的类型为nvarchar,则会占用两个字节。正常情况下

How to return an nvarchar(max) in a CLR UDF?

回眸只為那壹抹淺笑 提交于 2019-12-09 14:58:03
问题 Assuming following definition: /// <summary> /// Replaces each occurrence of sPattern in sInput with sReplace. This is done /// with the CLR: /// new RegEx(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace). /// The result of the replacement is the return value. /// </summary> [SqlFunction(IsDeterministic = true)] public static SqlString FRegexReplace(string sInput, string sPattern, string sReplace) { return new Regex(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace); }

Converting nvarchar(4000) to nvarchar(max)

試著忘記壹切 提交于 2019-12-08 17:26:43
问题 We have a few tables in our SQL Server (2005 & 2008) database with columns defined as nvarchar(4000). We sometimes need to be able to store more data than that and consider to use nvarchar(max) instead. Now to the questions. Are there any performance implications we should know of? Is it safe to use "alter table" to do the actual migration or is there another way? Anything else we should know before we convert? Regards Johan 回答1: We've had to do this as well in a few spots We didn't see any

How to convert TIMESTAMP values to VARCHAR in T-SQL as SSMS does?

◇◆丶佛笑我妖孽 提交于 2019-12-08 15:09:11
问题 I am trying to convert a TIMESTAMP field in a table to a string so that it can be printed or executed as part of dynamic SQL. SSMS is able to do it, so there must be a built-in method to do it. However, I can't get it to work using T-SQL. The following correctly displays a table result: SELECT TOP 1 RowVersion FROM MyTable It shows 0x00000000288D17AE . However, I need the result to be part of a larger string. DECLARE @res VARCHAR(MAX) = (SELECT TOP 1 'test' + CONVERT(BINARY(8), RowVersion)