如何在 SQL Server 的列中插入长字符串值

本文关键字:插入 字符串 SQL Server | 更新日期: 2023-09-27 18:33:45

INSERT INTO [Bitflow].[dbo].[GlobalConfiguration]
           ([Key]
           ,[Value]
           ,[Description]
           ,[DATE_LAST_UPDATED]
           ,[DATE_CREATED])
     VALUES
           ('OPERATIONS_BES_USERS_SQL_QUERY_01'
           ,'select DisplayName,EmailAddress,RelayServer, ModelName, PhoneNumber, PIN, 
HomeNetwork, ActiveCarrier, ICCID, 
             convert(varchar(10),CreationDate, 101)CreationDate,convert(varchar(10),ActivationDate, 
101)ActivationDate, 
             MsgsForwarded, MsgsSent,convert(varchar(10),LastFwdDate, 101)LastFwdDate,convert
(varchar(10),LastSentDate, 101)LastSentDate, 
             CurrentPolicyName, ServiceName from TEMP_BESselect 
DisplayName,EmailAddress,RelayServer, ModelName, PhoneNumber, PIN, HomeNetwork, 
ActiveCarrier, ICCID, 
             convert(varchar(10),CreationDate, 101)CreationDate,convert(varchar(10),ActivationDate, 
101)ActivationDate, 
             MsgsForwarded, MsgsSent,convert(varchar(10),LastFwdDate, 101)LastFwdDate,convert
(varchar(10),LastSentDate, 101)LastSentDate, 
             CurrentPolicyName, ServiceName from TEMP_BES'
           ,'Query for respective Bes Server'
           ,CAST(0x0000A2A600000000 AS DateTime), CAST(0x0000A2A600000000 AS DateTime))
GO

第二个值是一个巨大的字符串,通过存储它nvarchar(max)从 c# 代码检索时有很多空格想要删除它。在 C# 中检索 nvarchar(max) 值的兼容数据类型是什么?我想检索此值

如何在 SQL Server 的列中插入长字符串值

我认为您可以使用常见的SqlCommand

对于第二个参数,您可以执行以下操作

cmd.Parameters.Add("@Value", SqlDbType.VarChar);
cmd.Parameters["@Value"].Value = longString;

其中longString是查询参数

我猜您是通过 C# 应用程序生成上述查询的。 使用以下命令消除多个空格:

http://msdn.microsoft.com/en-us/library/xwewhkd1%28v=vs.110%29.aspx

string input = "This is   text with   far  too   much     whitespace.";
string pattern = "''s+";
string replacement = " ";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);