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
Solved

Need some help writing an SQL statement.

Posted on 2011-03-08
4
494 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
  • 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 40

Accepted Solution

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

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

789 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