Click here to Skip to main content
15,914,924 members
Home / Discussions / Database
   

Database

 
GeneralMSDE Setup.Exe and Reinstall Pin
Blake V. Miller25-Jan-05 18:28
Blake V. Miller25-Jan-05 18:28 
QuestionCOMException--Why? Pin
mysorian25-Jan-05 18:02
professionalmysorian25-Jan-05 18:02 
AnswerRe: COMException--Why? Pin
tojamismis27-Jan-05 7:45
tojamismis27-Jan-05 7:45 
GeneralRe: COMException--Why? Pin
mysorian27-Jan-05 17:11
professionalmysorian27-Jan-05 17:11 
GeneralBitwise operators in a SELECT statement Pin
Luis Alonso Ramos25-Jan-05 10:31
Luis Alonso Ramos25-Jan-05 10:31 
GeneralRe: Bitwise operators in a SELECT statement Pin
Michael Potter27-Jan-05 4:12
Michael Potter27-Jan-05 4:12 
QuestionCan I use a generic schema.ini file? Pin
MongooseNX25-Jan-05 9:50
MongooseNX25-Jan-05 9:50 
Generalupdate with conversion Pin
Jesse Evans25-Jan-05 9:11
Jesse Evans25-Jan-05 9:11 
Hi, folks.

[UPDATE]
I managed to figure it out on my own. First problem was using insert. I should have been using update. Second was figuring out how to assign a single value from the select statement. Here's what finally worked:

update data_75Q set elapsed_seconds = es<br />
from (select idnum, <br />
cast(left(elapsed_time, patindex('%:%', elapsed_time)-1) as int)*60 + <br />
cast(right(elapsed_time, 2) as int) as es<br />
from data_75Q) as t1<br />
where data_75Q.idnum = t1.idnum


Anyway, I had no answers from CodeProject, but just posting the question was enough to get me to think harder about the problem. For that, I thank all of you!Big Grin | :-D
[/UPDATE]


I have a MS SQL database that has a problem. One of the columns is supposed to be the elapsed time for a given process and has a varchar datatype. The process inserts the elapsed time value as a string, 'mm:ss', which means I can't perform time-related math on it. For instance, if I return a query into a spreadsheet and try to calculate statistics, it won't work.

So, I want to convert the string 'mm:ss' entries into time values. There does not seem to be a time datatype, so I want to convert the entries into an int datatype (which I can then call seconds).

I can write a query that selects the strings and converts them into int seconds:

select top 5 elapsed_time, cast<br />
(left(elapsed_time, patindex('%:%', elapsed_time)-1) as int)*60 + <br />
cast(right(elapsed_time, 2) as int) as secs<br />
 from data_75Q


returns:

elapsed_time                                       secs        <br />
-------------------------------------------------- ----------- <br />
10:30                                              630<br />
02:27                                              147<br />
03:44                                              224<br />
13:05                                              785<br />
13:52                                              832<br />
<br />
(5 row(s) affected)


This seems to work ok.

However, I can't figure out how to get the converted values back into the table. I added another column, elapsed_seconds as int, but I can't seem to figure out the proper syntax to use this in an INSERT statement. Here's what I've tried:

insert into data_75Q (elapsed_seconds) <br />
values <br />
select <br />
cast(left(elapsed_time, patindex('%:%', elapsed_time)-1) as int)*60 + <br />
cast(right(elapsed_time, 2) as int)<br />
from data_75Q


Although I've used the same select statement, Query Analyzer reports "Incorrect syntax near the keyword 'select'".

Thanks in advance for any help.

'til next we type...
HAVE FUN!! -- Jesse
Generalmultivalued fields at ado recordset Pin
moses32125-Jan-05 8:25
moses32125-Jan-05 8:25 
GeneralDatabase Logging Pin
Aaron Schaefer24-Jan-05 11:33
Aaron Schaefer24-Jan-05 11:33 
GeneralRe: Database Logging Pin
tojamismis27-Jan-05 7:58
tojamismis27-Jan-05 7:58 
GeneralEditing/Saving a record selected in a Listbox Pin
frank2124-Jan-05 9:58
frank2124-Jan-05 9:58 
GeneralView Pin
Sebastien Lachance24-Jan-05 4:25
Sebastien Lachance24-Jan-05 4:25 
GeneralRe: View Pin
Mike Ellison24-Jan-05 6:17
Mike Ellison24-Jan-05 6:17 
Generalinsert /retrieve text file into/from MySQL Pin
kd834124-Jan-05 4:08
kd834124-Jan-05 4:08 
GeneralRe: insert /retrieve text file into/from MySQL Pin
David Salter24-Jan-05 10:28
David Salter24-Jan-05 10:28 
GeneralRe: insert /retrieve text file into/from MySQL Pin
kd834125-Jan-05 9:21
kd834125-Jan-05 9:21 
GeneralRe: insert /retrieve text file into/from MySQL Pin
kd834125-Jan-05 9:22
kd834125-Jan-05 9:22 
GeneralRe: insert /retrieve text file into/from MySQL Pin
David Salter28-Jan-05 5:43
David Salter28-Jan-05 5:43 
QuestionDataTable &gt; DataView &gt; ComboBox? Pin
work_to_live24-Jan-05 3:11
work_to_live24-Jan-05 3:11 
AnswerRe: DataTable &gt; DataView &gt; ComboBox? Pin
tojamismis27-Jan-05 8:08
tojamismis27-Jan-05 8:08 
GeneralRe: DataTable &gt; DataView &gt; ComboBox? Pin
work_to_live27-Jan-05 13:18
work_to_live27-Jan-05 13:18 
GeneralRe: DataTable &gt; DataView &gt; ComboBox? Pin
work_to_live27-Jan-05 13:22
work_to_live27-Jan-05 13:22 
Generalconnecting to the data source Pin
Civic0624-Jan-05 1:38
Civic0624-Jan-05 1:38 
GeneralRe: connecting to the data source Pin
David Salter24-Jan-05 10:26
David Salter24-Jan-05 10:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.