sql

How to implement reverse geocoding on SQL Server 2008 (with spatial capabilities)?

Let's suppose I have a street shapefile loaded on SQL Server 2008. How can I implement a reverse geocode function (get an address from a lat/long pair)? What SQL Spatial functions can I use for that? Does it have a function that get the closest "feature" from a lat/long pair? ...

Getting @@IDENTITY from TableAdapter

I am trying to complete a seemingly simple task that has turned into a several hour adventure: Getting @@Identity from TableAdapter.Insert() Here's my code: protected void submitBtn_Click(object sender, EventArgs e) { AssetsDataSetTableAdapters.SitesTableAdapter sta = new AssetsDataSetTableAdapters.SitesTableAdapter(); int ins...

How do I change the "Indexed: Yes (No Duplicates)" constraint in Access to "Indexed: No" via SQL?

I need to change a column in MS Access from indexed to non-indexed. I need to do this via SQL because I do not have direct access to the database. I only have access to it via SQL. How do I do this? ...

Weird Select Result

Hi All, I have a table with an ID field of INT Type. I am doing some data validation and noticed that SELECT * from mytable where id=94 and SELECT * from mytable where id='94' works perfectly, but if I use SELECT * from mytable where id='94dssdfdfgsdfg2' it gave me the same result! How is this possible? ...

Interesting and challenging self join problem SQL Server 2005

I have this table named OrdersToCall Data types: All bigints, except for date which is a datetime |-Order Num-|----Date--- |- Primary Ph -| Secondary Ph | Alternate Ph |----101----| 02-07-2010 | 925-515-1234 | 916-515-1234 | 707-568-5778 |----102----| 02-07-2010 | 925-888-4141 | 925-888-4141 | 000-000-0000 |----103----| 02-07-2010 ...

query multiple updates

how do I do multiple updates within same query. Lets say I have this query UPDATE table1 SET Order = 1 WHERE ID = 1234 But I want to change some more orders where IDs are 2345 and 2837 and 8399 how would I do that within same mysql query. Please notice that Order may be different than 1 for those. as order field is unique. ...

Mysql select statement

I need a proper way to write a simple WHERE, AND, OR statement. This one doesn't work: SELECT `content` FROM `bx_wall_events` WHERE `type` = 'wall_common_text' OR `type` = 'wall_common_fb' OR `type`= 'wall_common_tw' AND `owner_id`='{$iId}' ORDER BY `date` DESC LIMIT 1 ...

Truncate with condition

Hi, truncate ->this resets the entire table, is there a way via truncate to reset particular records/check conditions. For ex: i want to reset all the data and keep last 30 days inside the table. Thanks. ...

Is there a reason that the primary key is nchar while other fields are nvarchar?

I am working through an example from MSDN that uses a small database to demonstrate data driven testing, and here is the simple schema: CREATE TABLE dbo.LogonInfoTest ( UserId nchar(256) NOT NULL PRIMARY KEY CLUSTERED, Password nvarchar(256) NULL, IsValid bit NOT NULL ) ON [PRIMARY] GO My question is: What is the under...

Select rows from SQL where column doesn't match something in a string array?

Let's say I have a table, Product, with a column called ProductName, with values like: Lawnmower Weedwacker Backhoe Gas Can Batmobile Now, I have a list, in Notepad, of products that should be excluded from the result set, i.e.: Lawnmower Weedwacker Batmobile In my real-life problem, there are tens of thousands of records, and thou...

Query help - self referential parent table

I have three tables: Type --------------------- TypeID (primary key) ParentTypeID (foreign key) TypeDescription (...) Action --------------------- ActionID (primary key) TypeID (foreign key) ReferenceID (foreign key) Reference --------------------- ReferenceID (primary key) ReferenceDescription (...) Type is self referential. Actio...

Nested aggregate and subquery in postgresql/SQL with grouping

I need to do the same group by on a bunch of different aggregates that I'm getting with nested subqueries in Postgresql 8.3. If I do this: select f10 as report_id, (SELECT AVG(age) FROM (select f10 as report_id, f62 as age from reports where f55 in ('1')) ...

How do I get LIKE and COUNT to return the number of rows less than a value not in the row?

For example: SELECT COUNT(ID) FROM My_Table WHERE ID < (SELECT ID FROM My_Table WHERE ID LIKE '%4' ORDER BY ID LIMIT 1) My_Table: X ID Y ------------------------ | | A1 | | ------------------------ | | B2 | | ------------------------ | | C3 | | -----------------------...

Help with TSQL join query

Based on below 2 tables declare @t1 table ( Id int, Title varchar(100), RelatedId int ) insert into @t1 values(1,'A',2) insert into @t1 values(1,'A',3) declare @t2 table ( Id int, Title varchar(100) ) insert into @t2 values (2,'B'), (3,'C') I am trying to get the below output Id Title RelatedItems -------...

How to SQL SUM on With Statement?

Query: ;WITH SuperSelect AS ( SELECT DISTINCT DropshipPackinglist.CaseNumber AS 'CASE NO.', DropshipPackinglist.Quantity AS 'QTY' FROM DropshipPackinglist JOIN HuaweiDescription ON DropshipPackinglist.ItemNumber = HuaweiDescription.ItemNumber WHERE (DropshipPackinglist.BatchCode ='0003721008190AHWA01KG')) SELE...

Help with SQL Query, is this possible?

I'm developing a system to process recurring billing for members. Items to be purchased can be grouped together for a special package rate, or purchased individually for a higher, stand-alone rate. The portion of my database schema that determines the amount to be paid for recurring items consists of the following 4 tables: MEMBER_RECUR...

Database Options for Blackberry

Okay, I'm new to blackberry development and I was wondering if anyone could give me a list of database options available for blackberry applications? What do developer's "normally" do when faced with the requirement of utilizing a server for their blackberry applications? Is there any one specific database that is used for a majority of ...

creating database in oracle10g

In mysql i can create a new database so easily just by writing a command. Mysql>create database database_name; In oracle 10g the default database name is XE. Can anybody tell command to create a new database other than XE ? I am using Linux(fedora-12). ...

Java PreparedStatement Syntax

Is this the correct syntax for a prepared statement in java: INSERT INTO table (id, version, data) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE data = IF(version > values(version), data, values(data)), version = IF(version > values(version), version, values(version)) I am looking for the best way to insert or update millions ...

Create a sql foreign key constraint

I wish to create a constraint that state as below Code.CodeTable ( CodeID smallint, CategoryID smallint,....) --> Parent Table Admin.Document( DocumentTypeID smallint,.....) --> Child Table The FK will be Admin.Document.DocumentTypeID map with Code.CodeTable.CodeID I wish to have the constraint that only check Code.CodeTable.CodeID...