|
hilbiazhar wrote: I want the increment to be totally automatic Title claims otherwise.
hilbiazhar wrote: should occur without any interference( i mean without accessing it A computed column would be calculated when it's value is requested. Why should it be without any interference? If you don't look at the number, then what is the use of incrementing it in the first place?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Oh i got it now. Actually I had not understood it properly. Thanks for making it clear anyway. Definitely this would be a good approach than keeping SQL Job Schedules like you said.
|
|
|
|
|
/* 2:Display the patient_id, patient_name, phone number( +91-999-999-9999 format) , type_of_ailment .
type of ailement is decided with the number of days stay in hospital.
if stay <=5 ---- Minor
if stay >5 and <=15 days ----Medium
if stay >15 days ---- Major */
I have 2 tables room_allocation and patient_master where pid is the primary key of patient_master table and it also happens to be foreign key in room_allocation table.
1)Columns of patient_master table are(pid Varchar(5) Primary Key,
name Varchar(20) Not Null,
age int Not Null,
weight int Not Null,
gender Varchar(10) Not null,
address Varchar(50) Not Null,
phoneno varchar(10) Not Null,
disease Varchar(50) Not Null,
doctorid Varchar(5) Not Null,
constraint patient_master_doctorid_fk foreign key(doctorid) references doctor_master(doctorid))
2)columns of room_allocation table are
(room_no varchar(5),
pid varchar(5),
adm_date date,
release_date date,
constraint room_allocation_room_no_fk foreign key(room_no) references room_master(room_no),
constraint room_allocation_pid_fk foreign key(pid) references patient_master(pid))
--------------------------------------------------------------------------
I have written the following querry for above question but it gave a syantax error.
-------------------------------------------------------------------------
select p.pid,p.name,concat(
case (release_date-adm_date)
when (release_date-adm_date)<=5 then
when ((release_date-adm_date)>5 and (release_date-adm_date)<=15) then
else
end as
from patient_master p,room_allocation r
when (release_date-adm_date)<=5 then minor
when (release_date-adm_date)>5 and when (release_date-adm_date)<=15 then med
from patient_master p,room_allocation r
where p.pid=r.pid ;
|
|
|
|
|
Look at your query closely, and you will see that you have duplicated the when clauses in the second half of the query
select p.pid,p.name,concat('91-',p.phoneno),
case (release_date-adm_date)
when (release_date-adm_date)<=5 then 'minor'
when ((release_date-adm_date)>5 and (release_date-adm_date)<=15) then 'medium'
else 'Major'
end as 'type_ailment'
from patient_master p,room_allocation r
when (release_date-adm_date)<=5 then minor
when (release_date-adm_date)>5 and when (release_date-adm_date)<=15 then med
from patient_master p,room_allocation r
where p.pid=r.pid ;
Everyone dies - but not everyone lives
|
|
|
|
|
Thanx for replying.I have duplicated the when clauses but I need to test for each condition so what can be the exact alternative.I tried removing the second when clause and replaced it with else clause but still it does not work.Should I go for nested if.
|
|
|
|
|
select p.pid,p.name,concat('91-',p.phoneno),
case
when (release_date-adm_date)<=5 then 'minor'
when (release_date-adm_date)<=15 then 'medium'
else 'Major'
end as 'type_ailment'
from patient_master p,room_allocation r
where p.pid=r.pid
|
|
|
|
|
Thank You very much it worked.
|
|
|
|
|
Good day to all,
Why tinyint(3) of mysql is treated as sbyte in .net(c#).
I cant find any official datatype mapping for .net and mysql out there.
|
|
|
|
|
|
sorry but still dont get it.
example: var t = typeof(reader[0]);
the "t" is a type of sbyte, i was expecting it to be int or short.
could be the value matter also?
BTW i dont use (example: reader[0].toInt()) for a purpose.
|
|
|
|
|
The link I gave you shows the mapping: tinyint maps to a single byte which, in computer memory, is a signed byte. This allows you to promote it to an integer without the necessity of any data conversion.
Explained in slightly more detail at http://dev.mysql.com/doc/refman/5.1/en/integer-types.html[^].
|
|
|
|
|
ohh thank you so much, now i understand it.
|
|
|
|
|
I'm experimenting with having multiple threads performing INSERTs into a table (no SELECTs, UPDATEs, or DELETEs) and I'm curious how the various IsolationLevels[^] affect performance. I have tried a few and seen no big differences. The documentation and what other information I have seen online (including here) has always seemed pretty vague to me -- and really only talks about reads (which aren't pertinent in this case).
Anyone have any insight on how IsolationLevel affects INSERTs?
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
PIEBALDconsult wrote: and really only talks about reads Because that's what could give trouble; if thread 1 does an partial update on a table, while thread 2 is reading that table - do you want the old or the new values in your result for thread 2?
I don't see any problems when multiple threads insert data. That is, if they are values - if you are reading within that insert-statement (a select, like say, the count of this table), then you might have above problem again.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: if they are values
Right, just simple insertion of values, no reading.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
Rec_ID Rec_Name Dist_ID
1 A 1
2 B 1
1 AA 2
2 AB 2
3 C 2
How can i write a Insert sql script for this table, eg: i should insert Rec_ID 3 while inserting Record for Dist_ID 1 and also Rec_ID 4 for Dist_ID 2, Suppose if many users inserting from different places, how to handle this situation. what is the best method? I have following 2 ideas, which is right idea or is there any other method to implement this
1) Select Max(Rec_ID) for the district, suppose if 2 people inserting at the same time will be a issue.
2) Put a Lock in the Stored Procedure
|
|
|
|
|
Specifying Rec_ID as an identity[^] column may do all of that work for you.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
I Cannot set it as Identity column, because based on the District ID should get the Next Rec_ID
|
|
|
|
|
In which case I do not understand what you are trying to do.
Can you specify exactly what you need with a before and after example - thanks.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
modified 6-Jun-14 9:14am.
|
|
|
|
|
I'm with Guy. This does not make any sense.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Wrong order.
Insert the records in the dependent tables first, and get their identity. Then insert the REC using the identities you fetched.
Inserting data in multiple tables, appearing as a single atomic operation would require a "transaction".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
And if the workload isn't too heavy you could use a Web Service (WCF or similar) to provide a single access point so the clients don't actually touch the database. The service could then perform the actions one-by-one.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
I have the following three tables:
TABLE_A TABLE_B TABLE_C
------- --------- -------
id (primary) tablea_id (foreign) tablea_id (foreign)
name boards text
date
phone
I have the following query to select all rows from TABLE_A and also count how many related rows are in each of the other two tables:
SELECT *, (SELECT COUNT(TABLE_B.tablea_id) FROM TABLE_B WHERE TABLE_B.tablea_id == TABLE_A.id) AS Cnt1, (SELECT COUNT(TABLE_C.tablea_id) FROM TABLE_C WHERE TABLE_C.tablea_id == TABLE_A.id) AS Cnt2 FROM TABLE_A
This works fine, but I was curious if: 1) SQL was doing three separate queries behind the scene, and 2) a more efficient way exists.
Thank you.
- DC
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
If you turn on the Execution Plan SSMS will show you the 3 queries and their relative costs. I often use this tool to compare the performance of queries constructed differently to do the same job.
I would use 3 union queries but I'd bet the cost is identical on such a simple query.
Sorry I missed the SQL Lite platform in the title
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Sorry I missed the SQL Lite platform in the title That's okay. I could've qualified it further by stating it's running on an Android platform.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|