Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In this query why we use '<>' symbol?

eg:
SQL
IF NOT EXISTS(SELECT CompanyCode
                  FROM CompanyMaster
                  WHERE CompanyCode=@CompanyCode AND [Status]=True AND CompanyID<>@CompanyID)
Posted

<> means Not equal to
Happy Coding!
:)
 
Share this answer
 
you can use != (not equal to) instead of <>

SQL
IF NOT EXISTS(
       SELECT CompanyCode
       FROM   CompanyMaster
       WHERE  CompanyCode = @CompanyCode
              AND [Status] = TRUE
              AND CompanyID != @CompanyID
   )
 
Share this answer
 
A run through the idiom, then ...
Take the data:
<root>
  <HEADER>
    <company_code>GULMOHAR</company_code>
    <batch_date>13/01/2011</batch_date>
  </HEADER>
  <kycdata>
    <app_updtflg>01</app_updtflg>
    <app_pos_code>GULMOHAR</app_pos_code>
    <app_type>I</app_type>
    <app_no>00001</app_no>
    <app_date>02/01/2012</app_date>
    <app_pan_no>ABBDE1234J</app_pan_no>
    <app_pan_copy>Y</app_pan_copy>
    <app_exmt>N</app_exmt>
    <app_exmt_cat />
    <app_exmt_id_proof>01</app_exmt_id_proof>
    <app_ipv_flag>Y</app_ipv_flag>
    <app_ipv_date>13/01/2012</app_ipv_date>
    <app_gen>M</app_gen>
    <app_name>SANDEEP CHAVAN</app_name>
    <app_f_name>HANMANT CHAVAN</app_f_name>
    <app_regno />
    <app_dob_incorp>05/10/1980</app_dob_incorp>
    <app_commence_dt />
    <app_nationality>01</app_nationality>
    <app_oth_nationality />
    <app_filler3 />
  </kycdata>
  <footer>
    <no_of_kyc_records>1</no_of_kyc_records>
    <no_of_addldata_records>0</no_of_addldata_records>
  </footer>
</root>

Now, imagine that this xml is tablulated in your database and you can query it:
SELECT [idx], [xml_in] FROM [cpqaAnswers].[cpqa].[tblFFIdx]; GO;

Running that query results in a single row of xml and it has an index of datatype [int] equal to "1". Try a hypothetical now:
DECLARE @cC [nvarchar](MAX)
SET @cC = '%<root>%'
DECLARE @cI [int]
SET @cI = 2		

(With a slight finnagle, omitting your conditional requirement of the "IF" clause and your first AND, do another query based on the same SELECT -> )
SELECT @cC FROM [cpqaAnswers].[cpqa].[tblFFIdx] WHERE CONVERT([nvarchar](MAX),[xml_in],2) LIKE @cC AND [idx]<>@cI

Your return is:
AVcs
~~~~~~~~
%<root>%

Now try that same query with @cI = 1 (you know this is true for the data, right?)
AVcs
~~~~

You get the empty set. By saying "not 1" the return will say "but there's only 1 ... so nothing". By changing @cC to 2, that "not 1" allows the return of the AVcs string as proscribed.
 
Share this answer
 
v3
Hi,

Check the links for Operator....

Comparison Operators (Transact-SQL)[^]
Operators (Transact-SQL)[^]
SQL Server Comparison Operators[^]

Regards,
GVPrabu
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900