views:

152

answers:

6

The TrackingData table is inside a database named Tracking. The stored procedure is being run inside the same database. I get data back with the query, but not with the SP.

SELECT *
    FROM
      dbo.TrackingData
      LEFT OUTER JOIN SSMain.dbo.EmailCampaignTracking ON (dbo.TrackingData.emailCampaginTrackingID = SShMain.dbo.EmailCampaignTracking.emailCampaignTrackingID)
      LEFT OUTER JOIN SSMain.dbo.EmailCampaigns ON (SSMain.dbo.EmailCampaignTracking.emailCampaignID = SSMain.dbo.EmailCampaigns.emailCampaignID)
      LEFT OUTER JOIN SpinStitchMain.dbo.EmailListAddresses ON (SSMain.dbo.EmailCampaignTracking.emailAddressID = SSMain.dbo.EmailListAddresses.emailAddressID)
    WHERE
      dbo.TrackingData.lattitude = 33.8322 AND 
      dbo.TrackingData.longitude =  -78.6491 and
      dbo.TrackingData.projectID = 131

CREATE PROCEDURE dbo.sel_Track_HitsByLatLong(
@latitude decimal(18,15),
@longitude decimal(18,15),
@projectID int
)
AS
BEGIN
 SELECT *
FROM
  dbo.TrackingData
  LEFT OUTER JOIN SSMain.dbo.EmailCampaignTracking ON (dbo.TrackingData.emailCampaginTrackingID = SSMain.dbo.EmailCampaignTracking.emailCampaignTrackingID)
  LEFT OUTER JOIN SSMain.dbo.EmailCampaigns ON (SSMain.dbo.EmailCampaignTracking.emailCampaignID = SSMain.dbo.EmailCampaigns.emailCampaignID)
  LEFT OUTER JOIN SSMain.dbo.EmailListAddresses ON (SSMain.dbo.EmailCampaignTracking.emailAddressID = SSMain.dbo.EmailListAddresses.emailAddressID)
WHERE
  dbo.TrackingData.lattitude = @latitude AND 
  dbo.TrackingData.longitude = @longitude and
  dbo.TrackingData.projectID = @projectID
END

Edit:

Turns out the numbers are getting zeros added to the end of them: 33.832200000000000

This has never happened befor an dnot sure what has changed. They get added when the prcedure is run.

+2  A: 

i would bet that it has to do with a conversion issue. Is TrackingData.lattitude and TrackingData.longitude really decimal(18,15) in your table?

can you replace the parameters in the SP with the two values in your first query and get the answer back? If so, then it's somewhere in the conversion when you are passing the parameters in.

Moose
YEs, they really are decimal(18,15) and yes, I can replace the params with teh valuse and it works fine.
DDiVita
How are you calling this? Through ado.net? with an exec statement? Show us the calling code - maybe we can see something there.
Ray
I'm running it, currently, in managment studio
DDiVita
@DDiVita, so, you hardcode the three parameters and your procedure works fine? This seems to indicate that Moose is correct, and your parameters aren't converting correctly. Have you tried putting some print statements into the procedure, to view @longitude and @latitude?
David Hall
try running it with an exec statement in ssms and see if you get a better result. Maybe visual studio is 'helping' you with your parameter values...
Ray
This is so strange. I have never run into this.
DDiVita
Ray, tried that too...No go.
DDiVita
Please post your exec statement - maybe there is a clue
Ray
DDiVita, I just did a quick test on SQL 2005, and it works just fine for me calling it like this: "testit 33.8322, -78.6491, 131" I am confused by the need for 15 decimal places in your latitude and longitude, are you tracking something down to the inch?
Moose
i even tried it with quotes around the values and it worked: testit '33.8322', '-78.6491', '131'
Moose
Here is what I am passing: EXEC [dbo].[sel_Track_HitsByLatLong] 33.8322, -78.6491, 131
DDiVita
I'm not exactly clear on some of the earlier comments... did you remove the parameters from your SP and replace (in the SP) the values? What were your results in that case? Not just passing the same values, but changing the query in the SP.
Tom H.
YEs, I removed the params from the SP and added the values directly to it. It worked fine.
DDiVita
A: 

Do you have access to SQL Server profiler? If so I would recommend catching a trace of what is actually being passed to the execute function as the parameters. Perhaps there is a precision problem with the values being passed to the SP. You think its 131 but you are getting 131.00000000000000000000000000001 instead.

GrayWizardx
This would only happen with float, not decimal
gbn
I would assume that it could happen with any "floating point" number do to the nature of how FP is done.
GrayWizardx
+1  A: 

I work with Lat's and Long's all the time - and I used to have DECIMAL(18,15) as the datatype.

I also had this problem :(

For me, it was a LOCALIZATION issue -> when a user from a non en-us/en-gb, etc.. location hit my site, the PERIOD was replaced with a COMMA. so i was trying to pass in 123,111 for a decimal value. fail. This means that, in my .NET application, the current thread's CultureInfo was getting auto set to the locale of the users connection (eg. es for spain, etc).

.
(for a .NET product/project)....

Try making sure u set the thread's cultureinfo to en-gb (that IS proper english, after all .. swipe!) and then seeing if the stored proc now works.

Too me -aaaaaagggggeeeeesssssss- to fix that bug :) u see, it always worked on my local machine (en-au) and as a query ... :)

good luck :)

Pure.Krome
ou know what, I think this may be my issue.....I'll write back
DDiVita
it sounds really weird ... but yeah, i kicked myself after I found this was an error, for us. I spent so much time reviewing the stored proc and just couldn't fault it! :) it was only after i was thinking "why do these decimals have comma's in them .. wtf? DING! i know...."
Pure.Krome
+1  A: 

Just as a FYI, latitude and longitudes having fifteen decimal digits of precision after the decimal is almost certainly excess precision. Near the equator, a precision of six digits corresponds to 11 centimeter (4.3 inch) resolution. Nine more orders of magnitude is well on the way to molecular size precision....

wallyk
The decmial type was suggested by a DBA who worked with geo location data. We can't really change it right now.
DDiVita
No problem. For sanity of comparisons, it would be reasonable to consider values equal if their difference is within an epsilon of 0.0001 degree (corresponding to 11 meters) if they are associated with objects the size of buildings, and 0.01 for medium sized cities (1.1 km).
wallyk
+1  A: 

What does this give you outside of the stored proc?

...
WHERE
  dbo.TrackingData.lattitude = CAST(33.8322 as decimal(18,15)) AND 
  dbo.TrackingData.longitude =  CAST(-78.6491 as decimal(18,15)) and
  dbo.TrackingData.projectID = CAST(131 as int)

Then add this the stored proc

SELECT @latitude, @longitude, @projectID

Between this, you should see exactly what the stored proc is working with and what the query returns when datatypes match

gbn
A: 

OK, so I changed the Lat and Long parameters to type of FLOAT. It works perfect now. I wasn't thinking that when sending the params as decimal(18,15), that it would add zeros to the end if the precision was lass than 15. Thanks to everybody who helped out with this.

DDiVita