【问题标题】:What is the size of a image field content in SQL Server?SQL Server 中图像字段内容的大小是多少?
【发布时间】:2012-04-04 21:21:27
【问题描述】:

我在 SQL Server 中有一个表。此表有一个图像字段,应用程序在其中存储文件。

有没有办法使用 T-SQL 读取图像字段中文件的大小?

【问题讨论】:

    标签: sql-server tsql datalength


    【解决方案1】:
    SELECT DATALENGTH(imagecol) FROM  table
    

    MSDN

    【讨论】:

    • 结果将是字节数
    • 兆字节 为单位,它将是 SELECT DATALENGTH(imagecol) / 1048576.0 FROM table
    【解决方案2】:

    不同的显示风格:

    SELECT DATALENGTH(imagecol) as imgBytes,
           DATALENGTH(imagecol) / 1024 as imgKbRounded,
           DATALENGTH(imagecol) / 1024.0 as imgKb,      
           DATALENGTH(imagecol) / 1024 / 1024 as imgMbRounded,
           DATALENGTH(imagecol) / 1024.0 / 1024.0 as imgMb
    FROM   table
    

    示例输出:

    imgBytes    imgKbRounded    imgKb       imgMbRounded    imgMb
    68514       66              66.908203   0               0.065340041992
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 2011-04-21
      • 2013-08-06
      • 1970-01-01
      相关资源
      最近更新 更多