|
try a bigint, in place of the int.. Care to explain why you are rounding the 50000, and what the casting is all about?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
To give a bit more history, we are creating this view to feed into another application so it has to be set length.
Suppose this view returns 100 rows, and I am having an arthimetic overflow in on row 56 only. I want to leave 56 and continue from 57. WhenI tried the try catch block, while it catches the error, but on once it hits 56, then the whole thing stops.
|
|
|
|
|
vanikanc wrote: To give a bit more history
Did you try what I suggested? Y/N?
vanikanc wrote: I want to leave 56 and continue from 57.
Filter the row out before casting it into infinity, make the result-variable bigger, or try padding it with zeroes after the cast.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I tried with bigint - still errored out.
|
|
|
|
|
vanikanc wrote: I tried with bigint - still errored out.
Was worth a shot.
right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8)
Where is the @dummy used here? 500 000 * 10 000 = 5 000 000 000. That's bigger than an int, and probably wider than eight characters. Some suggestions;
- Lose the round function
- Don't multiply by 10k, pad it with 4 zero's and save the string-representation.
- If the dummy needs be multiplied by 500k, then multiply it by 5 and pad zeroes again
- Don't limit the varchar to eight characters - use varchar(50)
What kind of number are you trying to display? Can you give us an example of a number "before" (the original dummy) and the one "after" (the resulting dummy)?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you for all your suggestions!
It is just some inherited code, and really don't know the in and out of it. It has been working for years, so don't want to mess with what comes in and goes out.
There was an error entering the value, it was supposed to be 50 and the user keyed in 500000. So, the business wants us to put aside such errors and continue processing the data. I guess we have to code for human errors!!
Thanks for all your time and suggestions!
|
|
|
|
|
vanikanc wrote: Thank you for all your suggestions!
My pleasure, hope I wasn't too rude.
vanikanc wrote: It is just some inherited code,
Ah, that's always a good one to include on the first post. If we see code, we assume you wrote it, and partially understand it.
vanikanc wrote: There was an error entering the value, it was supposed to be 50 and the user keyed in 500000. So, the business wants us to put aside such errors and continue processing the data.
On Error Resume Next indeed. That's not how engineers work; if it fails, it fails for a reason. It get's corrected or excluded beforehand, not ignored. It's how managers work; if it fails, and nothing is burning, it's not a problem. Just ship the damn product already, we'll fix the bugs later.
Perhaps this would be a good time to add a validator to the entry-field of that user, and sanitize his/her input before it gets into the system. Once the value has been entered, it should be treated as "correct".
You heard about Knight Capital? Seems they had an "On Error Resume Next" idea to, and the algo kept buying stocks in packages of 100 at a time, 20 to 25 times a second - for over an half hour! (Total >440 million* losses - let's just be glad they weren't a hospital and relying on that software)
Ignoring errors is the worst offence in IT; the system could have skipped customer 59 for all we know. The best approach is preached by (forgive me) PHP, and it's called "do or die". Either the app does what it should do, or there's an unexpected exception - and since we cannot guarantee that the we're still working with valid data (unexpected situation, who knows what variables are loaded and not?) we have only one realistic option; let the app die. Terminate.
That's always better than continuing and writing records with an outdated identity-value after an exception, and not nowing that you're corrupting a database that was still correct when the app died.
*) I checked this time whether I should use million or billion.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Hello Friends
I have 3 select statments I need to write all in one query How, is it works in MS SQL in Management Studio
Select E.FirstName +' ' + E.LastName as Supervisor
INNER JOIN [cgs].dbo.tems h ON(h.Supervisor = E.EmploId)
where h.temId = 336
Select E.FirstName +' ' + E.LastName as Agent
From [cgs].dbo.Employ E with (NoLock)
where E.EmploId = 2305
Select count(*) As Tras
From CGCSLF
Where Dispo = 'Tras'
Select count(*) As Comp
From CGCSLF
Where Dispo = 'Comp'
SELECT AgeID Sum(Hours) As HOURS
FromCGCSLF
Group By AgeID
Raman
Thank you in advance
|
|
|
|
|
I'm unclear what you require.
If you are using the ADO.net classes in SqlClient then you can put all those in one Command -- just separate them with semi-colons (;). You can then use ExecuteReader to get a DataReader to read the results -- use the NextResult method to advance to the results from the next statement. I'm fairly sure that DataAdapters will handle it as well, but I haven't used one for several years.
If you need to do something else, then please clarify your question.
|
|
|
|
|
hello sir,
I call this query in the program, before I do, I am testing query in the SQL management studio. In program Code is like that
String query = @"SELECT t.firstName + '' + t.LastName
Regards
Raman
|
|
|
|
|
I don't think you finished what you intended to write, but what you did write looks bad.
|
|
|
|
|
Raman samineni wrote: I have 3 select statments
Funny I count 5, the ability to count is reasonably fundamental to stating your problem. You also need to be much clearer what your goal is.
Do some reading on UNION and UNION ALL, these will help. Your queries must have the same fields and formats so your first query should be something like
Select E.FirstName +' ' + E.LastName as FullName, 'Supervisor' as TypeName
INNER JOIN [cgs].dbo.tems h ON(h.Supervisor = E.EmploId)
where h.temId = 336
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I put Union and Union all, it does not work.
Thanks
Regards
Raman
|
|
|
|
|
Did you do some reading on how to use UNION or did you just stick it in between the select queries. RTFM
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello sir,
Just stick in between the select queries. I dont want use Union , Because this qry goes to in the program.
Regards
Raman
|
|
|
|
|
Raman samineni wrote: I need to write all in one query
What would you gain from having it in a single statement? As PIEBALD stated, you can put them in a single SqlCommand and execute them.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Hello sir
Thank you. My out put was
Supervisor- AgentName-Hours-Tran-Completed,
when I ran the qry i need to get this report.
Regards
Raman
|
|
|
|
|
Raman samineni wrote: when I ran the qry i need to get this report.
You could put the other query in there too, as a subquery. The other queries might be combined, depending on "what" you are selecting from. I have not seen a corrected version of that code yet; I suggest you start writing and testing
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
hello sir,
How all three statments be written as one query.
Regards
Raman
|
|
|
|
|
how I will put in the sql Command all three query
Thanks
Raman
|
|
|
|
|
Raman samineni wrote: how I will put in the sql Command all three query
Do you need them in a single "sql statement", or do you need them in a single "SqlCommand"? For either way you have been given a solution - did they not work, and if so, what went wrong?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
send me both, No problem
Thanks
Raman
|
|
|
|
|
Raman samineni wrote: send me both, No problem
AFAIK, we're volunteers here. Why should I provide two pieces of code??
The first query from your list is simply invalid, as it lacks a FROM statement. You can search on the internet what a "subquery" is and how to write one, and try to combine that code as suggested. Also reread PIEBALDs' suggestions, there's a good reason they get upvoted every time.
Good luck, you'll need it
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
hello sir,
My OUT PUT Report was
SuperName Agent Name Hours Trans Compl
Thanks
Raman
|
|
|
|
|
I can't help you, sorry.
We gave quite some answers and options, and your response was "write them both for me". Unless you can answer whether you need them in a single SqlCommand or as a single Sql-statement, there will not be any progress.
Now, it doesn't add anything of value to have them in a single statement, but I'm willing to help. When I say "help", I mean that I can point out how some things are done, it does not mean that I am going to write YOUR code.
|
|
|
|