SQL Query - Server not found error

SQL Query - Server not found error

  

So, on a module I have two SQL queries.

When I test one of them, the generated SQL is

SELECT  [OSDEV1].DBO.[OSUSR_IB8_COMPANY_T12].[NAME],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[COMMITDATE],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[BUSINESSNAME],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[DOCNUMBER],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[LINENUMBER],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[DOCDATE],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[PARTNUMBER],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[PARTDESCRIPTION],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[MARKETINGPARTNUMBER],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[MARKETINGPARTDESCRIPTION],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[CUSTOMERPARTNUMBER],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[CUSTOMERPARTDESCRIPTION],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[PREVIOUSQUANTITY],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[PREVIOUSCANCELQUANTITY],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[PREVIOUSUNITPRICE],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[PREVIOUSMARKDOWN],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[PREVIOUSNETUNITPRICE],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[PREVIOUSLINETOTAL],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NEWQUANTITY],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NEWCANCELQUANTITY],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NEWUNITPRICE],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NEWMARKDOWN],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NEWNETUNITPRICE],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NEWLINETOTAL],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NETQUANTITY],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NETCANCELQUANTITY],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NETUNITPRICE],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NETMARKDOWN],
   [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[NETLINETOTAL],
   [OSDEV1].DBO.[OSSYS_USER_T12].[EMAIL]
FROM  [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS]
LEFT JOIN  [OSDEV1].DBO.[OSUSR_IB8_COMPANY_T12] ON  [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[COMPANYID] =  [OSDEV1].DBO.[OSUSR_IB8_COMPANY_T12].[ID]
LEFT JOIN  [OSDEV1].DBO.[OSSYS_USER_T12] ON  [OSDEV1].DBO.[OSSYS_USER_T12].[ID] =  [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[COMMITBY]
WHERE  [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[COMMITDATE] BETWEEN @BeginDate AND @EndDate
AND ( [OSDEV1].DBO.[OSUSR_AK0_BOOKINGS].[BUSINESSID] = @BusinessId OR @BusinessId = 0)
ORDER BY Name

Notice the [OSDEV1].DBO table name part everywhere.

This query works fine.

The other one generates the following SQL:

SELECT  [OSDEV1].DBO.[OSUSR_UUZ_BUSINESS9_T12].[BUSINESSNAME]
    ,  [OSDEV1].DBO.[OSUSR_AK0_SALESDOC5_T12].[DOCNUMBER]
    ,  [OSDEV1].DBO.[OSUSR_UUZ_DOCSUBTYPE3_T12].[DOCSUBTYPECODE]
    ,  [OSDEV1].DBO.[OSUSR_AK0_SHIPMENT2_T12].[PACKINGLISTNUMBER]
    ,  [OSDEV1].DBO.[OSUSR_AK0_SHIPMENT2_T12].[CREATEDATE]
    ,  [OSDEV1].DBO.[OSUSR_AK0_SHIPMENT2_T12].[SHIPPEDQUANTITY]
    ,  [OSDEV1].DBO.[OSUSR_AK0_SHIPMENT2_T12].[ISEXCLUDEFROMINVOICE]
    ,  [OSDEV1].DBO.[OSUSR_AK0_SHIPMENT2_T12].[ID]
FROM  [OSDEV1].DBO.[OSUSR_AK0_SHIPMENT2_T12]
JOIN  [OSDEV1].DBO.[OSUSR_AK0_SALESDOCLINESCHEDULE2_T12] ON  [OSDEV1].DBO.[OSUSR_AK0_SALESDOCLINESCHEDULE2_T12].[ID] =  [OSDEV1].DBO.[OSUSR_AK0_SHIPMENT2_T12].[SALESDOCLINESCHEDULEID]
JOIN  [OSDEV1].DBO.[OSUSR_AK0_SALESDOC5_T12].[ID] ON  [OSDEV1].DBO.[OSUSR_AK0_SALESDOC5_T12].[ID] =  [OSDEV1].DBO.[OSUSR_AK0_SALESDOCLINESCHEDULE2_T12].[SALESDOCID]
JOIN  [OSDEV1].DBO.[OSUSR_UUZ_DOCSUBTYPE3_T12] ON  [OSDEV1].DBO.[OSUSR_UUZ_DOCSUBTYPE3_T12].[ID] =  [OSDEV1].DBO.[OSUSR_AK0_SALESDOC5_T12].[DOCSUBTYPEID]
JOIN  [OSDEV1].DBO.[OSUSR_UUZ_BUSINESS9_T12] ON  [OSDEV1].DBO.[OSUSR_UUZ_BUSINESS9_T12].[ID] =  [OSDEV1].DBO.[OSUSR_AK0_SALESDOC5_T12].[BUSINESSID]
WHERE  [OSDEV1].DBO.[OSUSR_AK0_SHIPMENT2_T12].[COMPANYID] = @CompanyId
AND  [OSDEV1].DBO.[OSUSR_AK0_SHIPMENT2_T12].[CREATEDATE] BETWEEN @StartDate AND @EndDate

Notice the exact same  [OSDEV1].DBO table name part everywhere.

This one, however, gives the following error:

"Could not find server 'OSDEV1' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers."

Any one know why?

Thanks!

Carlos








Hi Carlos,

sorry for the late reply, did you manage to overcome the problem?

Regards!

Pedro

Turns out it was a PEBKAC.

If you look *really* close to the second SQL script you'll find this:

JOIN  [OSDEV1].DBO.[OSUSR_AK0_SALESDOC5_T12].[ID]

That is obviously incorrect.