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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Need help with a replacing query

Author  Topic 

G_Ozama
Starting Member

12 Posts

Posted - 2008-08-13 : 13:37:26
Hi I have a DB running on MSSQL 2000

I need to execute a query to do the following:

Inside the table named User there's a column named UserList and a column named UserType

UserList is varbinary type, 180 lenght
UserType is tinyint type, 1 lenght

The "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.
Go to Top of Page

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.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-13 : 15:16:14
moved from administration (2000)

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

G_Ozama
Starting Member

12 Posts

Posted - 2008-08-13 : 16:54:35
no one?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-14 : 14:46:47
Try casting it to varchar and use REPLACE
Go to Top of Page

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
Go to Top of Page

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')
Go to Top of Page

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 >.<
Go to Top of Page

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
Go to Top of Page

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')
Go to Top of Page

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?
Go to Top of Page

G_Ozama
Starting Member

12 Posts

Posted - 2008-08-21 : 22:15:27
anyone, plz?
Go to Top of Page

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=17

Webfred

Planning replaces chance by mistake
Go to Top of Page

G_Ozama
Starting Member

12 Posts

Posted - 2008-09-01 : 09:47:14
hey there's anyone who can help me here, please?
Go to Top of Page

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 = 0x0900001A0000280000FF0000126800286800FF0000FF0000

SET @SQL = 'SET @New = ' + REPLACE(master.dbo.fn_varbintohexstr(@Original), '280000', 'FF0000')

EXEC sp_executesql @SQL, N'@New VARBINARY(180) OUTPUT', @New OUTPUT

SELECT @New[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -