Click here to Skip to main content
15,890,741 members
Home / Discussions / Database
   

Database

 
GeneralRe: Export Data Pin
Tiger45616-Jan-06 17:39
Tiger45616-Jan-06 17:39 
Questiondsn confusion Pin
TofuBug2415-Jan-06 10:03
TofuBug2415-Jan-06 10:03 
AnswerRe: dsn confusion Pin
tuxyboy16-Jan-06 1:39
tuxyboy16-Jan-06 1:39 
Question[ACCESS 2003] create an SQL query Pin
Sasuko15-Jan-06 0:50
Sasuko15-Jan-06 0:50 
AnswerRe: [ACCESS 2003] create an SQL query Pin
Dave Kreskowiak15-Jan-06 16:42
mveDave Kreskowiak15-Jan-06 16:42 
QuestionFile xsd Pin
AlbePes14-Jan-06 23:06
AlbePes14-Jan-06 23:06 
QuestionCheck on table before adding Pin
gharry14-Jan-06 9:35
gharry14-Jan-06 9:35 
AnswerRe: Check on table before adding Pin
Colin Angus Mackay15-Jan-06 1:02
Colin Angus Mackay15-Jan-06 1:02 
gharry wrote:
IF(SELECT Horse_name, Horse_FEI From FEI WHERE Horse_Name LIKE inputName%)=True Then
IF(SELECT IDHorse From Boekelo_Horses WHERE Horse_ID = FEI.Horse_FEI)= True Then
Get all data and show edit screen
END IF
END IF


The structure you are looking for is something like this:
IF EXISTS(SELECT * FROM FEI 
          INNER JOIN Boekelo_Horses AS bh ON bh.Horse_ID = FEI.Horse_FEI
          WHERE Horse_Name LIKE @inputName)
BEGIN
    SELECT 1;
END
ELSE
BEGIN
    SELECT 0;
END


You can then call this SqlCommand with ExecuteScalar() and it will return a 1 for true, and 0 for false. Your calling application can then decide to take appropriate action depending on the outcome.

I've also taken your two SQL statements and rolled them in to one as they were disjointed, the second IF statement seemed to need input from the first that it was never going to get.

In a IF EXISTS(SELECT ....) structure, the list of columns in SELECT is ignored so you don't need to specify them, and specifying * is about the only time it is not inefficient to do that as the Query Optimiser already knows it needs no fields, it is just looking for one row with any data before it will stop processing the statement.

ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

QuestionList of NT Users In Server Domain SQL Server Pin
Bob Zagars14-Jan-06 8:28
Bob Zagars14-Jan-06 8:28 
Questionprocedure and datetime Pin
dexom13-Jan-06 19:37
dexom13-Jan-06 19:37 
AnswerRe: procedure and datetime Pin
PolarbearDK14-Jan-06 4:56
PolarbearDK14-Jan-06 4:56 
AnswerRe: procedure and datetime Pin
Muhammad Javed Khan19-Jan-06 1:29
Muhammad Javed Khan19-Jan-06 1:29 
QuestionThoughts on how to load data... Pin
PolarbearDK13-Jan-06 13:41
PolarbearDK13-Jan-06 13:41 
QuestionSorting using BindingSource with master-detail relationships Pin
kooks2k13-Jan-06 12:48
kooks2k13-Jan-06 12:48 
QuestionADO Item Collection Mystery Pin
mjackson1113-Jan-06 12:22
mjackson1113-Jan-06 12:22 
AnswerRe: ADO Item Collection Mystery Pin
mjackson1114-Jan-06 10:11
mjackson1114-Jan-06 10:11 
Questionremoving "similar duplicates" from select results Pin
jszpila13-Jan-06 5:56
jszpila13-Jan-06 5:56 
AnswerRe: removing "similar duplicates" from select results Pin
Michael Potter13-Jan-06 10:49
Michael Potter13-Jan-06 10:49 
GeneralRe: removing "similar duplicates" from select results Pin
jszpila13-Jan-06 10:56
jszpila13-Jan-06 10:56 
QuestionUsing Grant Pin
Tiger45612-Jan-06 23:46
Tiger45612-Jan-06 23:46 
QuestionSQL 2005 ConnectionString Pin
victor_ba8512-Jan-06 20:25
victor_ba8512-Jan-06 20:25 
AnswerRe: SQL 2005 ConnectionString Pin
gharry12-Jan-06 22:12
gharry12-Jan-06 22:12 
AnswerRe: SQL 2005 ConnectionString Pin
jonathan1512-Jan-06 22:50
jonathan1512-Jan-06 22:50 
AnswerRe: SQL 2005 ConnectionString Pin
itoleck13-Jan-06 4:57
itoleck13-Jan-06 4:57 
GeneralRe: SQL 2005 ConnectionString Pin
Paul Conrad14-Jan-06 10:02
professionalPaul Conrad14-Jan-06 10:02 

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.