简体   繁体   English

SQL查询串联以创建文件路径

[英]SQL query concatenation to create file path

I need to create a file path from 3 columns in a SQL query. 我需要从SQL查询中的3列创建文件路径。 This will be utilized in a file once everything is completed. 一切完成后,它将在文件中使用。 I have tried using CONCAT and string methods for the columns but no luck. 我试过对列使用CONCAT和字符串方法,但是没有运气。 The query is provided below. 该查询在下面提供。

SELECT 
    dbo.TBIndexData.DocGroup, 
    dbo.TBIndexData.Index1 AS Title, 
    dbo.TBIndexData.Index2 AS Meeting_Date, 
    dbo.TBIndexData.Index3 AS Meeting_Number,
    dbo.TBIndexData.Index4 AS Meeting_Type, 
    dbo.TBIndexData.Index5 AS Doc_Name, 
    dbo.TBIndexData.Index6 AS Doc_Type,
    dbo.TBIndexData.Index7 AS Meeting_Page, 
    dbo.TBIndexData.Index8 AS Notes, 
    dbo.TBIndexData.Index9 AS TBUser, 
    dbo.TBIndexData.Index10 AS Date_Scanned, 
    CONCAT (dbo.TBPrimary.FileDir + '\' + dbo.TBPrimary.TimsFileID + '.' + dbo.TBPrimary.FileExtension) AS FilePath
FROM 
    dbo.TBIndexData
JOIN 
    dbo.TBPrimary ON dbo.TBIndexData.DocGroup = dbo.TBPrimary.DocGroup

In SQL Server 2008 you need something like 在SQL Server 2008中,您需要类似

SELECT I.DocGroup,
       I.Index1  AS Title,
       I.Index2  AS Meeting_Date,
       I.Index3  AS Meeting_Number,
       I.Index4  AS Meeting_Type,
       I.Index5  AS Doc_Name,
       I.Index6  AS Doc_Type,
       I.Index7  AS Meeting_Page,
       I.Index8  AS Notes,
       I.Index9  AS TBUser,
       I.Index10 AS Date_Scanned, 
       P.FileDir + '\' + CAST(P.TimsFileID AS VARCHAR(10)) + 
            '.' + P.FileExtension AS FilePath
FROM   dbo.TBIndexData I
       JOIN dbo.TBPrimary P
         ON I.DocGroup = P.DocGroup 

You shouldn't use schemaname.tablename in the SELECT list. 您不应在SELECT列表中使用schemaname.tablename This is not officially supported grammar . 不是官方支持的语法 Just use tablename or give an alias. 只需使用tablename或提供别名即可。

(Using two part names there can lead to confusing errors if calling properties of columns of CLR datatypes) (如果调用CLR数据类型的列的属性,则在此处使用两个部件名称可能导致混淆错误)

尝试将CONCAT与逗号一起使用

CONCAT (dbo.TBPrimary.FileDir, '\\', dbo.TBPrimary.TimsFileID, '.', bo.TBPrimary.FileExtension) AS FilePath

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM