Pages

Monday, June 2, 2014

Oracle Linked Server in Sql Server

EXEC sp_addlinkedserver 'OraCMSRFID', 'CMSRFID', 'MSDAORA', 'CMSRFID'
                                           name                   service name                        servicename

EXEC sp_addlinkedsrvlogin 'OraCMSRFID', false, 'sa', 'oraUID', 'OraPwd'

select * from openquery(OraCMSRFID, 'select * from tabemp')

If variable is blank then no where clause

use OR:
select * from yourTable
where @test = '' OR Agent = @test
if @test coming with null value (instead of ''), you must use:
select * from yourTable
where @test is null OR Agent = @test
And
case when @Status = 1 then tbl1.Status end != 'Done' Or
case when @Status = 2 then tbl1.Status end = 'Done' 

TSQL dummy where clause

This is common when a query is being built programatically, so for every condition you will add:
 AND (SOMECONDITION)
so the 1=1 starts the WHERE section, it is always true, and it doesn't hurt the performance.

1=1 is usually used at the top of the where clause for formatting reasons and for ease of debugging. It is correct syntax and has no bearing on the output of the actual query.