October 18, 2010 at 7:23 am
Hai,
I have Two tables.
1) Table name :A(Column name is Month_id)
2)table name :B(Column name is Month_id)
max of month id in a table A Should be more than max of month id in table B.
i want this result set
How can i write the Sp PLZ let me know
October 18, 2010 at 7:35 am
http://www.sqlservercentral.com/Forums/FindPost1006152.aspx
Looks like homework.
Am I wrong?
-- Gianluca Sartori
October 18, 2010 at 7:37 am
yes Safori ur wrong. i explained my problem clearly. but u didn't uderstand what can i do.
October 18, 2010 at 7:46 am
mss.prince (10/18/2010)
yes Safori ur wrong. i explained my problem clearly. but u didn't uderstand what can i do.
I don't understand the full depth of what you are trying to do either. "What can you do?" Well, I'd think that reading the article that Gianluca pointed you to in your other thread to add the appropriate information that we need to would be a start. Just in case you lost the link, it's the first one in my signature as well. It will walk you through how to provide some sample data and your expected outcome so that we can help you. Without it all you're likely to receive is a large amount of guessing and untested code, however if you'd like tested code that will work for your requirements, you might want to indulge us a bit and provide the requested information.
-Luke.
October 18, 2010 at 7:53 am
If I got things wrong I apologise.
Anyway it doesn't look like you read the article I recommended.
To get an answer you should state your question with the following elements:
1) Table definition scripts:
CREATE TABLE A(
id int NOT NULL PRIMARY KEY,
Month_id int
)
CREATE TABLE B(
id int NOT NULL PRIMARY KEY,
Month_id int
)
2) Some sample data:
INSERT INTO A VALUES (1, 1)
INSERT INTO A VALUES (2, 7)
INSERT INTO A VALUES (3, 3)
INSERT INTO A VALUES (4, 2)
INSERT INTO B VALUES (1, 3)
INSERT INTO B VALUES (2, 4)
INSERT INTO B VALUES (3, 1)
INSERT INTO B VALUES (4, 1)
3) Description of your problem and expected results based on the sample data:
"I want to return all rows that have a higher value for column 'Month_id' in Table A than in Table B"
Expected result:
id Month_id
-- --------
2 7
3 3
4 2
If you don't take the time to explain your problem properly, nobody will take the time to help you.
-- Gianluca Sartori
October 18, 2010 at 8:04 am
Gianluca Sartori (10/18/2010)
If you don't take the time to explain your problem properly, nobody will take the time to help you.
Quite right. I have been guilty of this in the past and got the answer I deserved.
There are some very clever and smart people on this forum, but even they would not claim to be mindreaders (although they seem to be sometimes).
October 18, 2010 at 8:40 am
INSERT INTO A VALUES (1, 1)
INSERT INTO A VALUES (2, 7)
INSERT INTO A VALUES (3, 3)
INSERT INTO A VALUES (4, 2)
INSERT INTO B VALUES (1, 3)
INSERT INTO B VALUES (2, 4)
INSERT INTO B VALUES (3, 1)
INSERT INTO B VALUES (4, 1)
Table A
-----------
id, month
1,1
2,7
3,3
4,2
here we will find the max Month ( 7 is the max month)
Table B
-------
1,3
2,4
3,1
4,1
here also we find the max month(here 4 is the max month)
my requirement
if (7 (table a Max Month) > 4( table max Month))
variable message = true
else
varibale message = false
end
i need this requirement in SP
October 18, 2010 at 8:48 am
CREATE PROCEDURE testMaxValues
AS
BEGIN
SELECT CASE
WHEN (SELECT MAX(MonthId) FROM TableA) > (SELECT MAX(MonthId) FROM TableB) THEN 'True'
ELSE 'False'
END
END
-- Gianluca Sartori
October 18, 2010 at 12:48 pm
mss.prince (10/18/2010)
Hai,I have Two tables.
1) Table name :A(Column name is Month_id)
2)table name :B(Column name is Month_id)
max of month id in a table A Should be more than max of month id in table B.
i want this result set
How can i write the Sp PLZ let me know
What result set?
If you want the rows where month ID in table B are higher than the max month ID in table A, it might look something like:
select *
from TableB
where MonthID > (select max(MonthID) from TableA);
If that's not what you need, then you need to clarify your request.
I'm assuming English isn't your primary language based on the grammar, etc., in your posts. What (if any) language are you more comfortable with?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 9 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply