Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ramyasre
Starting Member
16 Posts |
Posted - 2011-04-30 : 02:30:56
|
| The following is an output of a table Name ID Month Year Q.Id Answer Survey_id Feedback_id--------------------------------------------------------------------Ms .Anita 10201 7 2010 2 52 1 1Ms .Anita 10201 7 2010 3 55 2 2Ms .Anita 10201 7 2010 4 65 3 3Now my query is when i am entered the same month and year value need to show error message.How can i show the error message |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-04-30 : 08:12:35
|
I suspect there is more to the logic than what you described - for example, if the year and month is for a different userid, do you still want to consider that as an error? But, only based on what you described, the query can be something like this:declare @year int; set @year = 2010;declare @month int; set @month = 7;if exists (select * from yourTable where @year = [year] and @month = [month]) select 'Error! year and month exists in table'else select 'No error'; |
 |
|
|
|
|
|