If you just need the value from the XML variable, you can directly use the value method and use sql:variable in the XPath expression:
SELECT @XML.value('(/book/author[.=sql:variable("@author")])[1]', 'nvarchar(50)')
If you have XML in the table and you need rows that have an author, you can use exist .
select * from YourTable where XMLCol.exist('/book/author[.=sql:variable("@author")]') = 1
And then you can, of course, combine them.
select XMLCol.value('(/book/author[.=sql:variable("@author")])[1]', 'nvarchar(50)') from YourTable where XMLCol.exist('/book/author[.=sql:variable("@author")]') = 1
source share