I need to create a file path from 3 columns in a SQL query. 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. 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
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. This is not officially supported grammar . Just use tablename
or give an alias.
(Using two part names there can lead to confusing errors if calling properties of columns of CLR datatypes)
尝试将CONCAT与逗号一起使用
CONCAT (dbo.TBPrimary.FileDir, '\\', dbo.TBPrimary.TimsFileID, '.', bo.TBPrimary.FileExtension) AS FilePath
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.