Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need some help writing an SQL statement.

Posted on 2011-03-08
4
Medium Priority
?
498 Views
Last Modified: 2012-05-11
I use Spiceworks on my network at work, and I need an update sql statment that will replace the existing ID file anywhere there are ticket ID numbers with a number that is 10109000 less than what is there. I foolishly thought setting a number that was the date was a good way to go for the helpdesk tickets. I was wrong. I know that purchases, comments and tickets all the use and link tickets together by their ID, and I've looked through the other tables, but I probably missed something. It's been awhile since I wrote any SQL and my guess is that someone can post it quickly for me.

So, in a nutshell I need to replace the ticket ID with a number that is 10109000 less than what exists now. For example:

ID = 10110015 would be changed to 1015. (10110015 - 10109000) = 1015

0
Comment
Question by:JBHale
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35074960
Update <your table> set ID=ID-10109000
0
 
LVL 4

Expert Comment

by:Alex Matzinger
ID: 35075007
I'm sorry, i got caught up with the last little bit, and forgot to include the condition.  Could you please give me an example of when you would like to update the ID.  Such as you have ID1 ID2 and ID3, and you need ID1 changed becasue ID3=X but ID2 doesn't need to be changed because it equals Y...or somtehing like that.  Thank You.
0
 
LVL 41

Accepted Solution

by:
Sharath earned 1000 total points
ID: 35075085
Probably you can add a WHERE conditio to update only those IDs which are greater than 10109000.
Update your_table set ID = ID - 10109000 WHERE ID > 10109000 

Open in new window

0
 
LVL 4

Expert Comment

by:dwkd
ID: 35075159
if i read correctly what you meant to say i believe this is your query:

WITH highestID AS ( SELECT Max(ID) FROM TABLE_NAME )
UPDATE TABLE_NAME
SET ID=ID-10109000
WHERE ID BETWEEN (highestID-10109000) AND highestID
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question