我正在使用此語法,如果只有它沒有出現錯誤,它應該工作得很好。SQL Server:類似於語法和添加運算符錯誤
SELECT
e.user_key,
e.char_key,
CONVERT(VARCHAR,substring(e.char_data, 9, 16)) AS name,
p.CHAR_DATA
FROM
CHAR_DATA0 AS e
INNER JOIN
CHAR_DATA1 AS p ON e.CHAR_KEY = p.CHAR_KEY
WHERE
p.CHAR_DATA LIKE '%'+CAST(cast(reverse(CONVERT(BINARY, 9998)) as BINARY(2)) AS BINARY(2))+'%'
ORDER BY
char_key
我需要幫助。如何更改此代碼以使其正常工作?
CHAR_DATA
列型BINARY(2000)
我有數據,像這樣:(得到它使用select)
0x04005C03020F2789080100000F278908010000FFFFFFFFFFFFFF0E2787080100000E278708010000FFFFFFFFFFFFFFBA3B8C08000000BB3B8C080000000F2789080100000F278908010000FFFFFFFFFFFFFF0E2787080100000E278708010000FFFFFFFFFFFFFFBC3B8C08000000BD3B8C080000000F2789080100000F278908010000FFFFFFFFFFFFFF0E2787080100000E278708010000FFFFFFFFFFFFFFBE3B8C08000000BF3B8C080000000F2789080100000F278908010000FFFFFFFFFFFFFF0E2787080100000E278708010000FFFFFFFFFFFFFFC03B8C08000000C13B8C08000000B5388B08020000B5388B08020000FFFFFFFFFFFFFF0E2787080100000E278708010000FFFFFFFFFFFFFFBA3B8C08000000BB3B8C08000000B5388B08020000B5388B08020000FFFFFFFFFFFFFF0E2787080100000E278708010000FFFFFFFFFFFFFFBC3B8C08000000BD3B8C080000000E2789080100000E278908010000FFFFFFFFFFFFFF0E2787080100000E278708010000FFFFFFFFFFFFFFBE3B8C08000000BF3B8C080000000E2789080100000E278908010000FFFFFFFFFFFFFF0E2787080100000E278708010000FFFFFFFFFFFFFFC03B8C08000000C13BFFFF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF0F27FFFF0100000F27FFFF0100000E2789080000000E278908000000FFFFFFFFFFFFFF7E107F08000000EC168408000000B0177D080000000F27FFFF0100000F27FFFF0100000E2789080000000E27890800000052167C081E000052167C081E0000E2167D08000000271F2005000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF0E2787080100000E27870801000052167C081E000052167C081E0000FFFFFFFFFFFFFF13127F08000000C813FFFF1E0000C813FFFF1E00000E2787080100000E27870801000028127A08000000BF3B2D05000000FFFFFFFFFFFFFF13127F08000000C813FFFF1E0000C813FFFF1E0000FFFFFFFFFFFFFFFFFFFFFFFFFFFF28127A08000000FFFFFFFFFFFFFF1B1A80081A00001B1A80081A0000E915FFFF1B0000E915FFFF1B000023067A0800000024147B0800000020120D05000000084792080100001B1A80081A00001B1A80081A0000E915FFFF1B0000E915FFFF1B000025067A0800000024147B0800000020120D05000000E21610050000000000009D000000FFFF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
我需要的地方尋找那些行,如果它包含我試圖進入找到。
我試圖找到的總是2個字節。所以我在上面的語法中尋找0x0E27。
這是一個工作的語法,但它不是我想做的事:
SELECT
CONVERT(INT,cast(reverse(substring(char_data, 37, 2)) as BINARY(2))) AS helm
FROM CHAR_DATA0
WHERE CHAR_KEY = 5
另一種是,如果我使用爲nvarchar(MAX),它給出了甚至不包含我想數據結果找到。
如果可能的話,我會盡量避免將這兩個字節放在一個單獨的字段中。你可以改變CHAR_DATA1表的設計(我懷疑不是,僅僅是因爲它的名字是「狡猾的」)。 – corlettk
對不起,但我無法更改設計。我堅持這個非常糟糕的設計,我需要鍛鍊。請指教。 :) – user1553142