【问题标题】:SQL Server : read full ntext column valueSQL Server:读取完整的 ntext 列值
【发布时间】:2013-08-15 22:06:10
【问题描述】:

我有aspnet_Tablename。请参阅下图进行数据设计。

现在,在PropertyValuesString 列上,数据以 xml 格式存储。

当我运行这个查询时。

SELECT TOP 10 [PropertyValuesString] FROM Table

我得到了结果,但不是PropertyValuesString 列的全部记录。

所以,任何人都告诉我。如何获取ntext 属性列的全部值?

也尝试过

select top 10 (max (convert(nvarchar(4000), PropertyValuesString))) FROM Table

DECLARE @ptrval varbinary(16)

SELECT @ptrval = TEXTPTR(data)
FROM TABLE1

READTEXT TABLE1.data @ptrval 0 500

这也只给出了部分文本,而不是完整的文本。

3) 我什至尝试查看它显示的企业管理器中的数据

<Long Text>

我还尝试通过“set testsize 60000”更改文本大小,以便我可以看到文本。

实际上是asp文件中的文本,在浏览器上可以看到,但我想在sql server中阅读。

但没有运气。

谢谢

【问题讨论】:

  • 首先 - ntext 已弃用 - 不要再使用它,并尽快将其替换为 nvarchar(max)。其次:您将获得该专栏的全部内容 - 请放心!只有 Management Studio 没有显示所有这些。您可以转到“选项”菜单并决定要查看多少此类列。另外:如果这是 XML - 你为什么不使用 XML 数据类型??
  • 假设我有超过 8000 列大小......那么如果我将 ntext 替换为 nvarchar(max) 会发生什么?
  • nvarchar(max)(还有XML!)可以保存最多2 GByte的数据(即10亿个字符在2-每个字符的字节 Unicode)!这比列夫·托尔斯泰 (Leo Tolstoj) 的《战争与和平》整本书的 100 倍多 - 这对你来说足够了吗??
  • 让我试试然后回到你身边...谢谢
  • 它将无法正常工作...bocz 我正在使用 aspnet dll...有 Web 服务...假设我将进行更改它将无法在我的 c# 代码中工作。所以,我必须必须放 ntext....

标签: sql-server stored-procedures ntext


【解决方案1】:

我终于得到了答案。

CREATE FUNCTION [dbo].[GetProfilePropertyValue] (  
    @PropertyName as varchar(max)
    , @PropertyNamesString as varchar(max)
    , @PropertyValuesString as varchar(max)) 
RETURNS varchar(max)
AS
BEGIN
    DECLARE @StartIndex int
    DECLARE @EndIndex int
    DECLARE @StartPos int
    DECLARE @Length int

    -- First we find the starting position
    Set @StartIndex = PatIndex('%' + @PropertyName + ':%', @PropertyNamesString) + LEN(RTRIM(@PropertyName)) + 3
    Set @EndIndex = PatIndex('%:%', Right(@PropertyNamesString, LEN(@PropertyNamesString) - @StartIndex))
    Set @StartPos = Cast(Substring(@PropertyNamesString, @StartIndex, @EndIndex) As Int)

    -- Now we need to know how long it is
    Set @StartIndex = @StartIndex + @EndIndex + 1
    Set @EndIndex = PatIndex('%:%', Right(@PropertyNamesString, LEN(@PropertyNamesString) - @StartIndex))
    Set @Length = Cast(Substring(@PropertyNamesString, @StartIndex, @EndIndex) As int)

    -- Now we get the value we want
    RETURN SUBSTRING(@PropertyValuesString, @StartPos + 1, @Length)
END

这很简单,现在我们需要做的就是运行一个获取信息的查询。

SELECT
    dbo.GetProfilePropertyValue('LastName', PropertyNames, PropertyValuesString)
    , dbo.GetProfilePropertyValue('FirstName', PropertyNames, PropertyValuesString)
    , dbo.GetProfilePropertyValue('Phone', PropertyNames, PropertyValuesString)
FROM aspnet_Profile

UserID 上加入aspnet_Users 将为您提供用户名和电子邮件。 享受。

【讨论】:

    【解决方案2】:

    看看Options (Query Results/SQL Server/Results to Grid Page)

    更具体地说是在

    检索到的最大字符数

    输入一个从 1 到 65535 的数字以指定最大数量 将在每个单元格中显示的字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-06
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      相关资源
      最近更新 更多