Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
john0990
Starting Member
4 Posts |
Posted - 2009-07-07 : 11:17:34
|
| Hello, I am having a problem concatenating a binary variable to a string. A simplified example:DECLARE @mybin1 binary(8)SET @mybin1 = 0x0000000000045F7CPRINT CONVERT(varchar(8), @mybin1) + ' TEST' The result is:strange characters.... + ' TEST'In the end I'm using an EXEC ('SELECT...') statement within my code, and want to use the binary value in a WHERE clause for filtering purposes. For example:DECLARE @mybin1 varchar(8)SET @mybin1 = CONVERT(varchar(8),0x0000000000045F7C)EXEC ('SELECT * FROM TestTable WHERE TimeStamp > ' + @mybin1)With this I get the following error:Msg 102, Level 15, State 1, Line 1Incorrect syntax near '|'.If I don't try to convert/concatenate the binary variable to the string it works as in this example:DECLARE @mybin1 binary(8)SET @mybin1 = 0x0000000000045F7CSELECT * FROM TestTable WHERE TimeStamp > @mybin1I think I need to convert the binary variable to a literal string '0x0000000000045F7C' for this to work. Any help would be appreciated! Thanks so much. |
|
|
john0990
Starting Member
4 Posts |
Posted - 2009-07-07 : 16:41:46
|
| Got the answer at another forum:DECLARE @mybin1 binary(8)SET @mybin1 = 0x0000000000045F7CPRINT CONVERT(varchar(8), @mybin1) + ' TEST'SELECT master.sys.fn_varbintohexstr(@mybin1) + ' TEST' |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|
|
|