Need some help writing an SQL statement.

Posted on 2011-03-08
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

Question by:JBHale
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

Expert Comment

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

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.
LVL 41

Accepted Solution

Sharath earned 250 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


Expert Comment

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

SET ID=ID-10109000
WHERE ID BETWEEN (highestID-10109000) AND highestID

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

632 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