Comparing Date With NULL Values

May 8, 2001

Hi , I need to compare two date fields in two different tables.One of the field is varchar(8) and other is dateime.When there is a date in one field and NULL in other field , how do I compare these two vales?

View 4 Replies


ADVERTISEMENT

Comparing NULL Values

Nov 2, 2006

I have two tables with the same structure / different data. I run a query between the tables to find the different records for the out put. When the values of the records or NULL, I do not get the output.


Code:

SELECT dbo.Closest3StoresB_RBT.CustomerPost, dbo.Closest3StoresB_RBT.ClosestStore1,
dbo.Closest3StoresB_RBT.ClosestStore2,
dbo.Closest3StoresB_RBT.ClosestStore3
FROM dbo.Closest3StoresB_RBT INNER JOIN
dbo.Closest3StoresB_OLD_RBT ON dbo.Closest3StoresB_OLD_RBT.CustomerPost =
dbo.Closest3StoresB_RBT.CustomerPost

WHERE
(dbo.Closest3StoresB_OLD_RBT.ClosestStore1 <> dbo.Closest3StoresB_RBT.ClosestStore1) OR
(dbo.Closest3StoresB_OLD_RBT.ClosestStore2 <> dbo.Closest3StoresB_RBT.ClosestStore2) OR

(dbo.Closest3StoresB_OLD_RBT.ClosestStore3 <> dbo.Closest3StoresB_RBT.ClosestStore3)




CustomerPost | ClosestStore1 | ClosestStore2 | ClosestStore3

I want to avoid seting the NULL values to '0' . Any suggestions?

View 3 Replies View Related

Comparing 2 Columns Containing Null Values

Sep 28, 2006

Hi All.

     I'm having some issues with what seems to be a simple update statement but is giving me grief when one or both of the columns I'm comparing are null. My statement (simplified) is as follows:-

 

UPDATE
 TAB_A
SET
 TAB_A.TRADCODE = TAB_B.TRADCODE
FROM
 TADS_STAGE.DBO.UNCLBRAMDEPT TAB_B
JOIN
 TADS.DBO.UNCLBRAMDEPT TAB_A
ON
 TAB_B.BRANCODE = TAB_A.BRANCODE
AND
 TAB_B.MERDCODE = TAB_A.MERDCODE
AND
(
 TAB_B.TRADCODE <> TAB_A.TRADCODE
)

 

If either of the TRADCODE fields (or both) are null then the comparison fails to return the row to update. I've tried setting the ANSI_NULLS setting to off, this has no effect, presumably because it will only work when comparing a column to a variable or evaluating if the column is null itself.

I've considered using ISNULL, but if one of the columns happens to contain the value that I specify as the replacement value then the comparison will result true and not include the row.

 

I'd be grateful for any pointers!

 

Thanks in advance

 

View 4 Replies View Related

Comparing To DateTimes In SQL-Select-Statement When One Date Can Be Null

Aug 25, 2007

Hello! I have a field "End" in my database that is mapped as DateTime and allows nulls. Now I want to do a SQL-Select (in a SqlDataSource) like SELECT * FROM My_Table Where (([End] = @EndDate) OR ([End] = null))  @EndDate is a valid DateTime, but the second OR condition doesn't work. What is the best way to check if the [End]-field is empty or null? Thank you very much! 

View 1 Replies View Related

Year (date) Totals Comparing To Column Values In Same Table?

Jan 31, 2014

how to write condition for self table year records, such 2012 name and acctno match with 2013 name and acctno then total, provided below,

create table #tab1 (MasterKey int, AcctNo varchar(12),name varchar(25), SumaofShares numeric, request_dat datetime )
--drop table #tab1
insert into #tab1 values (1000, 100,'Tom', 2500, '10/01/2012')
insert into #tab1 values (1001, 101,'Bat', 1550, '08/11/2012')
insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
insert into #tab1 values (1003, 103,'Vat', 1750, '04/15/2012')
insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')

[code]....

i would like to get 4 columns output

how to get sumofshares (#tab1) and TotalOutStanding(#tab2) summ up with these values,

MasterKey (#tab1) and IssueKey (#tab2) are like primary key and foreign key

so the request is

need to calculate, sumofshares (#tab1) and TotalOutStanding(#tab2) as below

1)ShareBenefist = U and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts UN Veriverted'
2)ShareBenefist = V and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts Veriverted'
3)ShareBenefist = N and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts NONVERT'
4)year( request_dat) =2102 and Name and Acctno not match with 2013 account name and acctno (#tab1)
then '2012 last year accounts'
5)year( request_dat) = 2013 and Name and Acctno not match with 2013 account name and acctno (#tab1)
then '2012 This year accounts'

for ex 1) the below accounts in #tab1 has both 2012 and 2013 and acctno same in both years and name is same in both years so it is condired as

insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')

for ex 2)

insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')

for ex 4) 2012 records there is not match acctno and name in 2013 recods

insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')

for ex 5) 2013 records there is no match of name and acct no with 2012 records

insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')

Expected Results (just for format)

AcctTypeDescription,SumofShares, OtotalutStand
'2012 and 2013 accts UN Veriverted',2700,234
'2012 and 2013 accts Veriverted' ,2890,234
'2012 and 2013 accts NONVERT' ,4533,325
'2012 last year accounts' ,2334,567
'2012 This year accounts' ,2222,877

View 9 Replies View Related

Transact SQL :: Date Time Casting - Comparing Values And If Not Same Then Populating Record

Sep 9, 2015

I am trying to pull the records which are being affected i.e, comparing the values and if not same then populating the record.

I am using the below condition in where clause however i am getting runt time error as "Conversion failure when converting date and/or time from character string"

Condition in Where clause:

cast(isNull(tab1.Col1,'') as datetime) <> cast(isNull(tab2.col1,'') as datetime) 

Note: Both col1 columns are of type nvarchar 

View 6 Replies View Related

Handling Null Date Values

Jun 30, 2000

I would like some suggestions on how to keep from displaying the value "1/1/1900" on my asp pages when my recordset field returns a Sql date value that is null

Thanks for any tips
Jim

View 1 Replies View Related

Null Date Values And Order By

Jul 20, 2005

How do I order a query by a date field ASC, but have any NULL valuesshow up last? i.e.7/1/20037/5/20037/10/2003<NULL><NULL>Any help will greatly be appreciated

View 3 Replies View Related

Handle Null Date Values

Feb 19, 2008



Hi,
In my Excel file, The Application date column contains empty for some rows. In SSIS I am using one Data Conversion to that Application Date column to change it as Date[dt_Date]. This data conversion is giving error Conversion failed. In Sqlserver table, I declare ApplicationDate column datatype as DateTime.
I want to keep those empty date values as Null in Sqlserver.
I tried the IMEX=1 property still it is not working. How to solve this error?

Thanks in advance.

View 1 Replies View Related

Configure SqldataSource With Null Date Values

Mar 20, 2008

I am attempting to create search parameters for a gridview control and I am experiencing a small issue. When I get to a date parameter I am unable to display null values.
I setup a sqldatasource and created the parameters below to handle the selections for minimum date required and the maximum date required for the date columns in the database. The problem is I do not know how to display null dates.
Is there a way to incorporate something into the search page to show null dataes? 
   
Sql Where Clause  1 WHERE (LSS_Requests.TypeCode = @TypeCode) AND (LSS_Requests.PersonNo LIKE '%' + @PersonNo + '%') AND
2 (LSS_Requests.TicketNo LIKE '%' + @TicketNo + '%') AND (LSS_Requests.Name LIKE '%' + @Name + '%') AND
3 (LSS_Requests.RequestName LIKE '%' + @RequestName + '%') AND (LSS_Requests.RequiredDate >= @Fromrequireddate) AND
4 (LSS_Requests.RequiredDate <= @ToRequiredDate) AND (LSS_Requests.OriginationDate >= @SearchFromOriginationDate) AND
5 (LSS_Requests.OriginationDate <= @SearchToOriginationDate) AND (LSS_Requests.LastUpdated >= @SearchFromUpdatedDate) AND
6 (LSS_Requests.LastUpdated <= @SearchUpdatedToDate) AND (LSS_Users_1.userFullName LIKE @SearchDDLUsers) AND
7 (LSS_Users.userFullName LIKE @SearchddlCIAsignee) AND (LSS_Requests.TypeCode = 'CC') AND (LSS_lu_Status.stNm LIKE '%' + @StatusName + '%')
  

View 2 Replies View Related

Inserting NULL Values On Date Fields Trhough DAL

Jul 25, 2006

I am using a DAL and i want to insert a new row where one of the columns is DATE and it can be 'NULL'.
I am assigning SqlTypes.SqlDateTime.Null.
But when the date is saved in the database, i get the minvalue (1/01/1900) . Is there a way to put the NULL value in the database using DAL????how can i put an empty date in the database?
THANK YOU!!!

View 3 Replies View Related

Date Selection Giving Default '1/1/1900' For NULL Values

Feb 9, 2005

'XXX_DTE' is character type which wont take NULL.

SELECT CONVERT(Datetime,XXX_DTE) FROM XXXX

I get result as : 1/1/1900

Why is it so.....

What I expect is '0000-00-00 00:00:00.000'

View 1 Replies View Related

Error Executing A Sql Statement Against A Table With Null Date Values

Apr 10, 2008

We are just upgrading a server from 2000 to 2005 and we are getting the message below when we execute a sql statement against a table with a date field with null values:


"Error converting data type DBTYPE_DBTIMESTAMP to datetime."

View 3 Replies View Related

Compressing Multiple Rows With Null Values To One Row With Out Null Values After A Pivot Transform

Jan 25, 2008

I have a pivot transform that pivots a batch type. After the pivot, each batch type has its own row with null values for the other batch types that were pivoted. I want to group two fields and max() the remaining batch types so that the multiple rows are displayed on one row. I tried using the aggregate transform, but since the batch type field is a string, the max() function fails in the package. Is there another transform or can I use the aggragate transform another way so that the max() will work on a string?

-- Ryan

View 7 Replies View Related

Lookup / Merge Join / Script - Howto Look Up Values By Comparing To A Range Of Values?

Jun 4, 2007

Hello all,

I am trying to think my way through a solution which I believe others have probably come across... I am trying to implement a matching routine wherein I need to match an address against a high value and a low value (or, for that matter an input date vs. a start and end date) to return the desired row ... i.e. if I were to use a straight vb program I would just use the following lookup:



"SELECT DISTINCT fire_id, police_ID, fire_opt_in_out, police_opt_in_out FROM ipt_tbl " & _

" WHERE zip_code = @zip_code AND addr_prim_lo <= @street_number AND addr_prim_hi >= @street_number " & _

" AND addr_prim_oe = @addr_prim_oe AND street_pre = @street_pre AND street_name = @street_name " & _

" AND street_suff = @street_suff AND street_post = @street_post " & _

" AND (expiry_date = '' OR expiry_date = '00000000' OR expiry_date > @expiry_date)" & _

" GROUP BY fire_ID, police_ID, fire_opt_in_out, police_opt_in_out"



My question, then, is how would you perform this type of query using a lookup / merge join or script? I have not found a way to implement a way to set the input columns? I can set the straight matches without a problem, i.e. lookup zip code = input zip code, but can't think of the correct way to set comparisons, i.e. lookup value 1 <= input value AND lookup value 2 >= input value



Any suggestions?



thanks for your time...

View 5 Replies View Related

Comparing Date Records In One Column To Know Missing Date Interval?

Jun 6, 2012

I need to compare the contents of a column.

I have a table with 1 column. Below are the sample contents..

DateInterval
2012-06-01 00:30:00.000
2012-06-01 01:00:00.000
2012-06-01 01:30:00.000
2012-06-01 02:00:00.000
2012-06-01 02:30:00.000

[code]....

as you can see, the records have a 30minutes time interval. i need to create a query to know if there are missing records in the table. so basically the result should be this:

DateInterval
2012-06-01 18:00:00.000
2012-06-01 20:30:00.000

if it is not doable, we can get the nearest record of all missing records like this:

DateInterval
2012-06-01 17:30:00.000
2012-06-01 20:00:00.000

or this:

DateInterval
2012-06-01 18:30:00.000
2012-06-01 21:00:00.000

or this:

DateInterval
2012-06-01 17:30:00.000
2012-06-01 18:30:00.000
2012-06-01 20:00:00.000
2012-06-01 21:00:00.000

View 6 Replies View Related

Comparing VarCHAR FIELD With NULL

Apr 20, 2006

Hi, I have the following query

SELECT *
FROM PABX
INNER JOIN LOGIN ON (PABX.COD_CLIENTE = LOGIN.COD_CLIENTE)
AND LEFT(LOGIN.TELEFONE1,3) = LEFT(PABX.NRTELEFONE,3)
LEFT JOIN AUXILIAR ON (AUXILIAR.ORIGEM=LOGIN.LOCALIDADE)
WHERE
pabx.COD_cliente = 224 and
SUBSTRING(PABX.NRTELEFONE,4,1) NOT IN ('9', '8', '7')
AND LOGIN.UF = RIGHT(PABX.LOCALIDADE,2)
AND LOGIN.LOCALIDADE <> PABX.LOCALIDADE
AND PABX.CLASSIFICA IS NULL
AND PABX.LOCALIDADE <> AUXILIAR.DESTINO
AND (BLOQUEADO = 0 OR BLOQUEADO IS NULL)



But It has a problem because when AUXILIAR.DESTINO returns null (it means there is no registry) the condition AND PABX.LOCALIDADE <> AUXILIAR.DESTINO doesn't work, like 'SAO PAULO' is different from 'NULL' but for my query no it's not even equal, and this condition ommit the results....how can I solve it ?

PS: Both auxiliar.destino and pabx.localidade is varchar(255)

Thanks

View 5 Replies View Related

Comparing Today's Date With Date In Field

May 19, 2008

I want to be able to compare today's date with the date that is in the database. Right now I have:

Select Field1, Field2
FROM table 1
Where Year(TS_Date)=Year('3/1/2006')and Month(TS_Date)=Month('3/1/2006')

Where I have to change the date every month. Is there a way to use GetDate or another type of code so it could automatically update every month.
Any suggestions would be very greatful.

View 13 Replies View Related

Transact SQL :: Comparing Two Tables By NOT NULL Cells In Different Columns

Oct 22, 2015

We have two tables:

Table1
Servers|Databases|Users|Names
Server1|Database1|User1|Name1
Server2|Database2|User2|Name2
Server3|Database3|User3|Name3
Server4|Database4|User4|Name4
Server5|Database5|User5|Name5

Table2
Servers|Databases|Users|Names
NULL    |Database1|NULL |Name1
NULL    |NULL        |User1|Name2
NULL    |NULL        |NULL |Name3
Server5|Database5|NULL |NULL

I need to check Table1 by Table2 only on NOT NULL cells and if all of them in the row match do not return that row as the result. In this case it will be:

Results:
Servers|Databases |Users |Names
Server2|Database2|User2|Name2
Server4|Database4|User4|Name4

I used query like this:

SELECT a.Server, a.Databases, a.Users, a.Names FROM Table1
EXCEPT
SELECT ISNULL(b.Server,c.Server), ISNULL(b.Databases,c.Databases), ISNULL(b.Users,c.Users), ISNULL(b.Names,c.Names) FROM Table2 AS a, Table1 AS c

But for many rows (like 100 000) it takes ages to get results, any better way to work on this? 

View 2 Replies View Related

Comparing Two Row Values

Jan 15, 2007

whats the best way to compare two row values and concatenate those two

For example

Table1
-------
Col1 Col2
----------
A 1
A 4
B 2
C 3
A 5

I need a query to return something like
"where (A=1 or A=4 or A=5) and (b=2) and (c=3)"

Thanks in advance

View 11 Replies View Related

Comparing Values

Feb 23, 2006

Hi All

I have 2 tables
dbo.aus

dbo.us

aus has column ausid

us has column usersid

how do i ran a query to filter out all matching values in the 2 tables
basically i want a list of values that are the same in both tables

thanks

View 3 Replies View Related

Comparing Values Within Same Table

May 1, 2014

I would like to compare some values in two columns which are in the same table. I want to check that there are no differences between the values if the ID is Test1 and Test2

Example table

IDValue1Value 2
TEST1HouseTango
TEST2HouseTango
with test as (
select * from ExampleTable where ID= 'TEST'
),

[Code] ....

View 4 Replies View Related

Comparing Values Within Database

Sep 10, 2007

Hi,

There are two tables in my Database, tb1 and tb2 which both have the same attribute ID. I would like to ensure that there is nothing in ID in tb1 which is not listed in ID in tb2, can anyone help?

Thanks for any info.

Albert.

View 10 Replies View Related

Comparing Time Values

Aug 25, 2005

I have a table called WorkItem. It models a chunk of work done duringa working day.It has two columns that I'm interested in:Start (smalldatetime) - the TIME the work block is begunDuration (int) - the duration in minutes of the work block.In another table called OvertimeRates I have information about ratemultipliers and a column that tells me the TIME that the ratemultiplier kicks in.e.g.OTRateBegins (smalldatetime)In terms of calculating whether a particular work block starts afterthe OTRateBegins, I could (I presume) do something like:If CONVERT(smalldatetime, Start, 108) > CONVERT(smalldatetime,OTRateBegins, 108)However, would I be better off using DATEPART functions to get the hourand minute parts of both the Start and OTRateBegins, and using theminstead? For some reason, (probably paranoia!), I am suspicious of theCONVERT function.Apologies for not posting DDL, but I felt that the situation didn'treally warrant it.ThanksEdward

View 6 Replies View Related

Comparing Column Values Among 2 Or More Rows

Jun 29, 2012

I've been working with T-SQL in a MSSQL Server Management Studio (2005) for about a week now. I've been trying to convert some horribly written VB code from a MS Access DB over to SQL so it can be automated on a SQL backend.

Most of the learning process and coding has gone surprisingly well. The problem is with comparing some data to determine which one needs to be flagged.

Three tables to note in bold, with notable fields in italics below them:

EmployeeData
HRID (identity)

ResourceAllocation
ID (identity)
[Last Name] (linked to HRID)
Project
[Resource Start Date]
[Resource End Date]
[Percent Utilization]

tblHCvalues
RAID (linked to ResourceAllocation.ID)
a monthyear and quarteryear for every month and quarter from 2012-2014. IE january12, february12, 1q12, 2q13, etc...

And yes, there are probably a thousand ways to optimize that tblHCvalues, but I'll ask about that later. Just work with the structure I have

Here's how it works: Each employee's data and unique HRID is in the EmployeeData tableAn employee can be on one or multiple projects at any timeThose projects are stored per project in the ResourceAllocation table with a link to the Employee's HRID, and all the other information listed aboveEven though an employee might be on two projects, they can only count for headcount on one project.

We use rules that compare the percent of work being done on a project, and the start and end dates of the employee (resource) on that project to determine which project should be counted for Headcount. The code uses a cursor to go through each HRID, and then pull up all the ResourceAllocation records associated with it.Run the rules to determine which ResourceAllocation record counts toward headcountA stored procedure then runs that fills out the tblHCvalues in the way we want for the project we want

All of it works, except for the rules that compare the things, so that's what I want to focus on in this thread. How do I write these rules:

Here are the rules, and they should work for any number of multiple resource allocations for one employee:

Choose the ResourceAllocation with the greatest [Percent Utilization]If the top ResourceAllocations have equal [Percent Utilization], choose the ResourceAllocation with the earliest [Resource Start Date]If the [Percent Utilization] and the [Resource Start Date] are equal, choose the latest [Resource End Date]If all three fields are equal, choose the first ResourceAllocation (aka, screw it and pick one at random)

I'm sure I could use a bunch of IF statements to compare it all, but even that is complicated to think about. There has to be an easier way, right?

View 6 Replies View Related

Comparing Result Set Values Of 2 Queries ??

Apr 20, 2004

Any assistance would be so helpful !!

We have 2 tables.. lets call them INV and COST

Table INV and COST have 3 related columns, namely ID,AMOUNT and VAT. As shown below...

ID | AMOUNT | VAT ( INV TABLE )
1 |20.125 |2.896
2 |10.524 |1.425

ID | AMOUNT | VAT ( COST TABLE )
1 |20.125 |4.821 .... different to ID 1 in INV Table
2 |10.524 |1.425

If you look above, I need to sum the AMOUNT and VAT columns and get a value for each ID, then compare the two tables and get the ID's that have different values...in this case I would need a result saying ID1 as the total of INV TABLE ID1 (23.021) is different to the corresponding ID1 row in COST TABLE (24.946)

Thats it ???

Please could someone out there offer some ideas ?

THANKS

JON

View 4 Replies View Related

Comparing Result Set Values Of 2 Queries ??

Apr 20, 2004

Any assistance would be so helpful !!

We have 2 tables.. lets call them INV and COST

Table INV and COST have 3 related columns, namely ID,AMOUNT and VAT. As shown below...

ID | AMOUNT | VAT ( INV TABLE )
1 |20.125 |2.896
2 |10.524 |1.425

ID | AMOUNT | VAT ( COST TABLE )
1 |20.125 |4.821 .... different to ID 1 in INV Table
2 |10.524 |1.425

If you look above, I need to sum the AMOUNT and VAT columns and get a value for each ID, then compare the two tables and get the ID's that have different values...in this case I would need a result saying ID1 as the total of INV TABLE ID1 (23.021) is different to the corresponding ID1 row in COST TABLE (24.946)

Thats it ???

Please could someone out there offer some ideas ?

THANKS

JON

View 1 Replies View Related

Comparing Result Set Values Of 2 Queries ??

Apr 20, 2004

Any assistance would be so helpful !!

We have 2 tables.. lets call them INV and COST

Table INV and COST have 3 related columns, namely ID,AMOUNT and VAT. As shown below...

ID | AMOUNT | VAT ( INV TABLE )
1 |20.125 |2.896
2 |10.524 |1.425

ID | AMOUNT | VAT ( COST TABLE )
1 |20.125 |4.821 .... different to ID 1 in INV Table
2 |10.524 |1.425

If you look above, I need to sum the AMOUNT and VAT columns and get a value for each ID, then compare the two tables and get the ID's that have different values...in this case I would need a result saying ID1 as the total of INV TABLE ID1 (23.021) is different to the corresponding ID1 row in COST TABLE (24.946)

Thats it ???

Please could someone out there offer some ideas ?

THANKS

JON

View 4 Replies View Related

Comparing Values And Inserting A Record

Apr 25, 2007

SELECTIndustry,
100.0 * SUM(CASE when ceoischairman = 'yes' then 1 else 0 end) / COUNT(DISTINCT CompID) AS [YesPercent],
100.0 * SUM(CASE when ceoischairman = 'no' then 1 else 0 end) / COUNT(DISTINCT CompID) AS [NoPercent]
FROMTCompanies
GROUP BYIndustry
ORDER BYIndustry

This code above is working as I need it but I need to insert some additional functionality. Thanks

I need to add something like this:

IF YesPercent > NoPercent
UPDATE tableX SET CEOIsChairman='Yes' WHERE Industry='<the industry value being evaluated>'
Else If NoPercent > YesPercent
UPDATE tableX SET CEOIsChairman='No' WHERE Industry='<the industry value being evaluated>'
Else
UPDATE tableX SET CEOIsChairman='Equal' WHERE Industry='<the industry value being evaluated>'
End

View 1 Replies View Related

COMPARING WITH COLUM WITH SPECIFIC VALUES IN SQL

Feb 6, 2008

Im Working with stored procedure. How can i compare Columns with specific values. I want to get the greater values of those column and inserted it to other columns. i want something like these
CASE
WHEN a> b,c,d THEN a
WHEN b> a,c,d THEN b
WHEN c> a,b,d THEN c
WHEN d> a,d,c THEN d

is there any ways to implement this? i got an error..
thanks please help..

View 7 Replies View Related

Comparing GPS Lat/Lon Values From Database Within An Area

Apr 2, 2008

Hi,

I would be very grateful if someone could help me. I have very little SQL knowledge and would like a push in the right direction:

I have a application that receives GPS lattitude and longitude values. I was originally using file base system where I would load all the points from the file into memory and do the calculations in the software but I now would like to use SQL Server Express.

I have created the tables:

[Table 1] GPS Points:
id int Primary key
latitude real
longitude real
desc nvarchar(128)

[Table 2] GPS Locations (comprises of one or more GPS Points from [1] above) to form a boundary:
GPS Locations database structure is:
locationId int primary key
gpspoint1 int
gpspoint2 int
gpspoint3 int
gpspoint4 int
desc nvarchar(128)

Table 2 contains up to 4 gps points ids from table 1 and GpsPoints1-4 can be null.

I have created the tables and I have inserted GPS values into both tables.

My problem:
I am trying to compare the current Lat/Lon (which are passed into the SQL fuction as two real datatype value) and I want to return all Table 2 locationId's where the current Lat/Lon are withing GPSPoints1-4 area.
gpspoint1, gpspoint2, gpspoint3, gpspoint4 reference an id from Table 1. I am not sure how I can do this?

I have implemetned a SQL function that returns all points from Table 1 that are within the predefined radius of 1.5 miles from the current Lat/Lon values passed in.

select desc,latitude,longitude, acos(SIN( PI()* @LatDec /180 )*SIN( PI()*latitude/180 )
)+(cos(PI()* @LatDec /180)*COS( PI()*latitude/180) *COS(PI()*longitude/180-PI()* @LonDec /180)
)* 3963.191 AS distance
FROM GpsPoints
WHERE 1=1
AND 3963.191 * ACOS( (SIN(PI()* @LatDec /180)*SIN(PI() * latitude/180)) +
(COS(PI()* @LatDec /180)*cos(PI()*latitude/180)*COS(PI() * longitude/180-PI()* @LonDec /180))
) < = Radius
ORDER BY 3963.191 * ACOS(
(SIN(PI()* @LatDec /180)*SIN(PI()*latitude/180)) +
(COS(PI()* @LatDec /180)*cos(PI()*latitude/180)*COS(PI() * longitude/180-PI()* @LonDec /180))
)

where 3963.191 is earths radius in miles,
radius is 1.5,
@LatDec is the current latitude and
@LonDec is the current longitude

Uses a lot of Trig and (for me) is quite complicated. This works very well and is very accurate. It also only uses a single table. I want to be able to now look for the current position within a boundary of 3 or more positions from Table 1 and this is where I am struggling?

Also, any suggestions on how I could do this better would be very much appreciated?

I look forward to your reply and help.

Thank you in advanced.

View 2 Replies View Related

Comparing Values Between 2 Matrices (matrix)

Jun 8, 2007

Hello
I have two matrices. One contains sales data for the current year, the other prior year. Both matrices use different data sets

I'd like to compare the two - possibly by creating a third matrix that subtracts prior year from current year.

Any ideas? When I create a third matrix and substitute a formula like =sum(values, "Data source for matrix 1") - sum(values, "Data source for matrix 2"), the resultant matrix subtracts the grand total from the first matrix - not the individual "cell".

Any suggestions are appreciated.
Thanks

View 4 Replies View Related

Comparing A Date Value In SQL Against Today's Date

Mar 29, 2006

I have a query that accesses a series of events in a gridview and would like to only show those that are in the future. I am looking to compare the date/time column against today's date in my SQL query.Any ideas would be great.ThanksOrbital

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved