<bdo id='rR6bJ'></bdo><ul id='rR6bJ'></ul>
    1. <i id='rR6bJ'><tr id='rR6bJ'><dt id='rR6bJ'><q id='rR6bJ'><span id='rR6bJ'><b id='rR6bJ'><form id='rR6bJ'><ins id='rR6bJ'></ins><ul id='rR6bJ'></ul><sub id='rR6bJ'></sub></form><legend id='rR6bJ'></legend><bdo id='rR6bJ'><pre id='rR6bJ'><center id='rR6bJ'></center></pre></bdo></b><th id='rR6bJ'></th></span></q></dt></tr></i><div id='rR6bJ'><tfoot id='rR6bJ'></tfoot><dl id='rR6bJ'><fieldset id='rR6bJ'></fieldset></dl></div>

      <legend id='rR6bJ'><style id='rR6bJ'><dir id='rR6bJ'><q id='rR6bJ'></q></dir></style></legend>
    2. <tfoot id='rR6bJ'></tfoot>

      1. <small id='rR6bJ'></small><noframes id='rR6bJ'>

      2. 在 sql server 中检查文件是否存在?

        Check for file exists or not in sql server?(在 sql server 中检查文件是否存在?)

        <i id='xFZ8q'><tr id='xFZ8q'><dt id='xFZ8q'><q id='xFZ8q'><span id='xFZ8q'><b id='xFZ8q'><form id='xFZ8q'><ins id='xFZ8q'></ins><ul id='xFZ8q'></ul><sub id='xFZ8q'></sub></form><legend id='xFZ8q'></legend><bdo id='xFZ8q'><pre id='xFZ8q'><center id='xFZ8q'></center></pre></bdo></b><th id='xFZ8q'></th></span></q></dt></tr></i><div id='xFZ8q'><tfoot id='xFZ8q'></tfoot><dl id='xFZ8q'><fieldset id='xFZ8q'></fieldset></dl></div>
          <tbody id='xFZ8q'></tbody>
          <bdo id='xFZ8q'></bdo><ul id='xFZ8q'></ul>
        • <tfoot id='xFZ8q'></tfoot>
        • <small id='xFZ8q'></small><noframes id='xFZ8q'>

            <legend id='xFZ8q'><style id='xFZ8q'><dir id='xFZ8q'><q id='xFZ8q'></q></dir></style></legend>

                  本文介绍了在 sql server 中检查文件是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  解决方案:http://www.tech-recipes.com/rx/30527/sql-server-how-to-check-if-a-file-exists-in-a-directory/

                  使用 stackoverflow 问题就这个问题发表了一篇文章来帮助他人.

                  Made a post about this question using stackoverflow question to help others.

                  id  filepath
                  
                  1   C:vishwanath21776656.docx
                  2   C:vishwanathvishs_srv_req_2009.txt
                  3   C:UsersdalviDWDW20SharedAmd64.exe
                  4   C:Usersdalvi1.txt
                  

                  我在我的数据库服务器中创建了这样的表,我在文件路径列中存储了文件路径,现在我必须使用 sql 检查文件是否存在于我的机器中,如果存在我需要添加临时我的表中的列显示是,如果存在,则不存在.

                  I've table like this created in my db server, I've stored file paths in it filepath column, now I've to check using sql whether the file exists in my machine, if it exists I need to add temporary column in my table showing yes if exists and no it doesn't exists.

                  我写的这段代码适用于 1 个文件,但我不知道如何将它用于我的表格.

                  I wrote this code which works for 1 file But I don't know how to use it for my table.

                  DECLARE @isExists INT
                  exec master.dbo.xp_fileexist 'C:vishwanath21776656.docx', 
                  @isExists OUTPUT
                  SELECT case @isExists 
                  when 1 then 'Yes' 
                  else 'No' 
                  end as isExists
                  

                  最终输出应该是这样的

                  id  filepath                                 Isexists
                  
                  1   C:vishwanath21776656.docx               Yes
                  2   C:vishwanathvishs_srv_req_2009.txt     Yes
                  3   C:UsersdalviDWDW20SharedAmd64.exe     Yes
                  4   C:Usersdalvi1.txt                      No
                  

                  推荐答案

                  像这样创建一个函数:

                  CREATE FUNCTION dbo.fn_FileExists(@path varchar(512))
                  RETURNS BIT
                  AS
                  BEGIN
                       DECLARE @result INT
                       EXEC master.dbo.xp_fileexist @path, @result OUTPUT
                       RETURN cast(@result as bit)
                  END;
                  GO
                  

                  编辑您的表并添加一个计算列(IsExists BIT).将表达式设置为:

                  Edit your table and add a computed column (IsExists BIT). Set the expression to:

                  dbo.fn_FileExists(filepath)
                  

                  然后只需选择:

                  SELECT * FROM dbo.MyTable where IsExists = 1
                  

                  更新:

                  在计算列之外使用函数:

                  To use the function outside a computed column:

                  select id, filename, dbo.fn_FileExists(filename) as IsExists
                  from dbo.MyTable
                  

                  更新:

                  如果函数为已知文件返回 0,则可能存在权限问题.确保 SQL Server 的帐户具有足够的权限来访问文件夹和文件.只读应该足够了.

                  If the function returns 0 for a known file, then there is likely a permissions issue. Make sure the SQL Server's account has sufficient permissions to access the folder and files. Read-only should be enough.

                  是的,默认情况下,网络服务"帐户没有足够的权限进入大多数文件夹.右键单击相关文件夹并选择属性",然后单击安全"选项卡.单击编辑"并添加网络服务".点击应用"并重新测试.

                  And YES, by default, the 'NETWORK SERVICE' account will not have sufficient right into most folders. Right click on the folder in question and select 'Properties', then click on the 'Security' tab. Click 'Edit' and add 'Network Service'. Click 'Apply' and retest.

                  这篇关于在 sql server 中检查文件是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                1. <i id='A9lXQ'><tr id='A9lXQ'><dt id='A9lXQ'><q id='A9lXQ'><span id='A9lXQ'><b id='A9lXQ'><form id='A9lXQ'><ins id='A9lXQ'></ins><ul id='A9lXQ'></ul><sub id='A9lXQ'></sub></form><legend id='A9lXQ'></legend><bdo id='A9lXQ'><pre id='A9lXQ'><center id='A9lXQ'></center></pre></bdo></b><th id='A9lXQ'></th></span></q></dt></tr></i><div id='A9lXQ'><tfoot id='A9lXQ'></tfoot><dl id='A9lXQ'><fieldset id='A9lXQ'></fieldset></dl></div>
                      <bdo id='A9lXQ'></bdo><ul id='A9lXQ'></ul>
                      <legend id='A9lXQ'><style id='A9lXQ'><dir id='A9lXQ'><q id='A9lXQ'></q></dir></style></legend>

                          <tfoot id='A9lXQ'></tfoot>

                        • <small id='A9lXQ'></small><noframes id='A9lXQ'>

                              <tbody id='A9lXQ'></tbody>