How to check a PAth existing uysing T SQL

  • HI,

    whenever I use the below script, it throws the below error. Any suggestion, what's going on wrong?

    declare @DbFilePath VARCHAR(max)

    set @DbFilePath = ' c:\mdndnd\mmnsn\'

    if object_id('tempdb.dbo.#fileExist') is not null

    drop table #fileExist

    create table #fileExist (

    fileExists int,

    fileIsDir int,

    parentDirExists int

    )

    insert into #fileExist

    exec xp_fileexist @DbFilePath

    declare @directory_check INT

    select @directory_check = [parentDirExists]

    from #fileExist

    IF @directory_check = 1

    BEGIN

    END

    Msg 0, Level 11, State 0, Line 0

    A severe error occurred on the current command. The results, if any, should be discarded.

    Thanks.

  • This works:

    declare @sql nvarchar(4000)

    set @sql= 'exec xp_fileexist ''' + @DbFilePath + ''''

    insert into #fileExist

    exec sp_executesql @sql

    Gerald Britton, Pluralsight courses

  • HI Britton,

    It works.,

    Thanks.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply