Solved

Need some help writing an SQL statement.

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now