473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Not able to update using LIKE % clause in MSSQL

10
Hi

I am relatively new to MSSQL.... when i am trying to fetch the data from table using this query.

update ticket set escalation=activity where escalation like '2008%31'

escalation and activity are both of datetime data type

Values in escalation column

2008-01-30 06:46:27.000
2008-01-30 09:24:36.000
2008-01-31 09:41:12.000
2008-01-31 10:07:00.000
2008-01-31 12:04:30.000
2008-01-31 12:34:58.000
2008-01-31 12:52:29.000

But when i run this query it updates the 7 rows

update ticket set escalation=activity where escalation like '%2008%'

Why is this so.... i need to have more detailed like clause so thati update correct rows.

Appreciate any help.

Thanks
Jan 31 '08 #1
3 3578
deepuv04
227 Expert 100+
Hi

I am relatively new to MSSQL.... when i am trying to fetch the data from table using this query.

update ticket set escalation=activity where escalation like '2008%31'

escalation and activity are both of datetime data type

Values in escalation column

2008-01-30 06:46:27.000
2008-01-30 09:24:36.000
2008-01-31 09:41:12.000
2008-01-31 10:07:00.000
2008-01-31 12:04:30.000
2008-01-31 12:34:58.000
2008-01-31 12:52:29.000

But when i run this query it updates the 7 rows

update ticket set escalation=activity where escalation like '%2008%'

Why is this so.... i need to have more detailed like clause so thati update correct rows.

Appreciate any help.

Thanks
since the datetime column you are comparison with text it is not working

so before comparing the column with like convert the datatype to varchar as follows

update ticket set escalation=activity where convert(varchar(20),escalation,20) like '2008%31'

or
update ticket set escalation=activity where convert(varchar(20),escalation,120) like '2008%31'


hope will help you..

thanks
Jan 31 '08 #2
Delerna
1,134 Expert 1GB
OOPs , my comment does not apply so I deleted
Jan 31 '08 #3
pks83
10
since the datetime column you are comparison with text it is not working

so before comparing the column with like convert the datatype to varchar as follows

update ticket set escalation=activity where convert(varchar(20),escalation,20) like '2008%31'

or
update ticket set escalation=activity where convert(varchar(20),escalation,120) like '2008%31'


hope will help you..

thanks
Thanks a lot it worked!!
Feb 1 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
1
by: Alberto | last post by:
Hello all, I'm new in this newsgroup and I apologise if my question has already done. Let me knwo if FAQ is avaible somewhere. I use msSQL server to manage data for a B2B portal. Orginal data...
3
by: Jerry | last post by:
Well, here is some weirdness. First, I noticed that I have 2 Set keywords (silly me). so I removed the 2nd "Set" but still got a syntax error. Then I removed the Where clause, and now it works...
12
by: Bill Moran | last post by:
Hey all. I've hit an SQL problem that I'm a bit mystified by. I have two different questions regarding this problem: why? and how do I work around it? The following query: SELECT GCP.id,...
4
by: Igor Kryltsov | last post by:
Hi, If you can help me to correct my mistake. To simplify my question: I have table: create table test ( name varchar(10),
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
2
by: Dima Gofman | last post by:
I have a trigger on UPDATE on a table. I'm running some maintenance UPDATE and DELETE queries which I want the trigger to ignore but at the same time I want other UPDATE queries that other users...
0
by: silversubey | last post by:
I am trying to convert mssql triggers to mysql. I am very new to Mysql and would like some help with my code. My queries work but there has to be a more efficient way to write them. I would greatly...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.