I’ve been working on a project in C# which at some point I need to compare two strings where their filename are the same,
SELECT Hash
FROM Beamer.PackageDetailFile (NOLOCK)
WHERE FileName = '"+fileName+"' ;
This is not working, table and column names are correct. However,
SELECT Hash FROM Beamer.PackageDetailFile (NOLOCK)
This code is giving me hashes.
What’s the problem? Please help thanks.
Problem solved, the fileName im calling was the directory path not the filename, that was the problem. Works fine now cheers to all
The query itself should be fine, although it is very bad practice, and should use parameters, i.e.
and add a parameter to the command called
filename, with the value from your local variable.Reasons this can fail:
'abc'is not equal to'AbC'(if CI, it is)[n]char(len)vs[n]varchar(len); a[n]char(len)is padded with whitespace on the right, which can give odd resultsN'{blah}'vs'{blah}'– mainly only an issue for non-ASCII “blah”[n]varchar(20)and your parameter is 80 characters long, it won’t match the trimmed version in the column