Author |
Topic |
G_Ozama
Starting Member
12 Posts |
Posted - 2008-08-13 : 13:37:26
|
Hi I have a DB running on MSSQL 2000I need to execute a query to do the following:Inside the table named User there's a column named UserList and a column named UserTypeUserList is varbinary type, 180 lenghtUserType is tinyint type, 1 lenghtThe "list" is setted by 6 numbers each item, ex.:0x0900001A0000280000FF0000126800286800FF0000FF0000 Where "FF0000" is a "null" value.I need to replace all "280000" with "FF0000" values, where UserType is 17, knowing that the "280000" can be at any part of the "list".Is there any query to do it?Thx in advance, and sorry for my english... |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-08-13 : 13:39:52
|
Post it in SQL 2000 Development. |
 |
|
mcrowley
Aged Yak Warrior
771 Posts |
Posted - 2008-08-13 : 14:41:18
|
There is no query to do it easily, because this is a violation of First Normal Form. |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-08-13 : 15:16:14
|
moved from administration (2000)_______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.0 out! |
 |
|
G_Ozama
Starting Member
12 Posts |
Posted - 2008-08-13 : 16:54:35
|
no one? |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-14 : 14:46:47
|
Try casting it to varchar and use REPLACE |
 |
|
G_Ozama
Starting Member
12 Posts |
Posted - 2008-08-14 : 23:16:51
|
quote: Originally posted by visakh16 Try casting it to varchar and use REPLACE
can u do a simple example 4 me please? im not very familiar with query, still learning |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-15 : 00:45:59
|
SELECT REPLACE(CAST (Yourfield AS varchar(100)),'280000','FF0000') |
 |
|
G_Ozama
Starting Member
12 Posts |
Posted - 2008-08-15 : 15:36:14
|
quote: Originally posted by visakh16 SELECT REPLACE(CAST (Yourfield AS varchar(100)),'280000','FF0000')
Disallowed implicit conversion from data type varchar to data type varbinary, table 'MyBase.dbo.User', column 'UserList'. Use the CONVERT function to run this query.I can't run the query with your sample, so i changed a bit to this:UPDATE User SET UserList = REPLACE(CAST(UserList AS varchar(100)),'280000','FF0000')so it returned me the error above...can't figure out how i can do this >.< |
 |
|
G_Ozama
Starting Member
12 Posts |
Posted - 2008-08-15 : 15:49:11
|
i did some "tests" here with this query, i understand its functionality... just cant understand why it dont work with the varbinary values |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-16 : 01:29:34
|
try this too:-UPDATE User SET UserList = REPLACE(CONVERT(varchar(100),UserList,1),'280000','FF0000') |
 |
|
G_Ozama
Starting Member
12 Posts |
Posted - 2008-08-16 : 07:51:07
|
quote: Originally posted by visakh16 try this too:-UPDATE User SET UserList = REPLACE(CONVERT(varchar(100),UserList,1),'280000','FF0000')
same error message as before, i think it's not possible to do it...i read somewhere about "Role" it'll be like the same for me if instead of making this query, it just auto-convert the 280000 into FF0000 when saving the data...so is there a way for me to "tell" sql to auto change 280000 into FF0000 when it add the values into the table? |
 |
|
G_Ozama
Starting Member
12 Posts |
Posted - 2008-08-21 : 22:15:27
|
anyone, plz? |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-08-22 : 04:18:21
|
UPDATE [User]SET UserList = convert(varbinary,REPLACE(CONVERT(varchar(180),UserList),'280000','FF0000'))where UserType=17WebfredPlanning replaces chance by mistake |
 |
|
G_Ozama
Starting Member
12 Posts |
Posted - 2008-09-01 : 09:47:14
|
hey there's anyone who can help me here, please? |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-01 : 11:10:28
|
[code]DECLARE @Original VARBINARY(180), @New VARBINARY(180), @SQL NVARCHAR(300)SET @Original = 0x0900001A0000280000FF0000126800286800FF0000FF0000SET @SQL = 'SET @New = ' + REPLACE(master.dbo.fn_varbintohexstr(@Original), '280000', 'FF0000')EXEC sp_executesql @SQL, N'@New VARBINARY(180) OUTPUT', @New OUTPUTSELECT @New[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|