sql

Cant figure out how to join these tables

Need help with some kind of join here. Cant figure it out. I want to loop out the forum boards, but I also want to get last_post and last_posterid from posts, and based on last_posterid get username from users. This is how far I've come yet (:P): SELECT name, desc, position FROM boards b INNER JOIN posts p ON ??? INNER JOIN users u ON...

How to select dynamically column from the table?

Hi All, I wrote a trigger for a table for insert ,update. For every insert and update, in the trigger I am comparing rows from 'Inserted' table and rows from 'Deleted' table. I need to get the affected column. How to do this? A B C D 1 2 3 5. I am updating B's value with 3. Then the trigger will fire. In that trigger, from deleted t...

Access SQL Server 2008 from Android?

I know there is already a question like this, but I have found this page on the Android Developemt site: http://developer.android.com/reference/java/sql/package-summary.html which seems to suggest that it is possible to interface to a SQL database. If this is possible then could someone please show me how it can be done. ...

Continuously synchronize tables between two databases

Hello, I have had my experience with MSSQL Server somewhat 6 years ago, so I have only basic knowledge of its workings now. The problem I'm posed with is that of syncing the databases between two live CRMs (NopCommerce and Rainbow Portal-based one if anyone's curious) running on the same DB server. The data I'm interested in is spread ...

Conditional insert sql server

Let's consider this basic insert insert into TableName (Col1,Col2,Col3) values (Val1,Val2,Val3) i want this insert to be done only if Val1 !=null and Val3!=null How to accomplish this? ...

Update on row for each group with max value in other column

I have to update a column in a very, very large table. So performance is a big issue. The question is the similar to this one, but only for Sybase Adaptive Server Enterprise (ASE 12.5.4) plus I need to do an update on the retrieved rows. Is there a way to do it without a self join like in the top voted answer for Oracle? This was the f...

Stored procedure - Passing a parameter as xml and reading the data

I have this stored procedure, that reads data from xml and make some inserts ALTER procedure [dbo].[SP_InsertIOs] @iosxml xml AS DECLARE @currRecord int -- parse the records from the XML EXECUTE sp_xml_preparedocument @currRecord OUTPUT, @iosxml BEGIN TRY INSERT INTO SN_IO ( [C1] ,[C2] ,[C3] ) SELECT [C...

How should date-based queries in Oracle be parameterised

ResultSet rs=st.executeQuery( "select j.vc_jo_no, j.dt_jo_date, p.vc_product_name from mst_jobcard j, mst_prod p where j.vc_product_code=p.vc_product_code and j.dt_jo_date=to_char("+tdate+","+"'"+dd-mm-yy+"'"+") "); In my specified query it should display the records based o...

How to insert selected value in insert statment in sqlserver

i need to insert 4 column in sql table fist 2 column i have type remain 2 column i have to get it from another table ..how combine and insert this in single query ...

Access SQL database remotely from iPhone app

I am trying to access an SQL database remotely. Can someone give me a hint or idea about how to do this in the iPhone? ...

Using T-SQL to read an XML feed directly into an XML field in a table?

I see a LOT of resources about producing feeds from T-SQL2005, about parsing XML into a database schema, processing, bulk operations, etc. What I don't see is how to have, for example, a statement/s in a stored proc or function which can simply access a URL for an XML feed, load the XML into a table field or sproc variable and close the...

how can i drop a table which i have declared in my SP..

like i declared a table... declare @tempTable TABLE (Id bigint identity(1,1), bKey int, DateT DateTime, Addres nvarchar(max), unit bigint) and i want to drop it...but im stucked coz drop table n truncate are not working. ani ideaaa...??? ...

MERGE INTO With between production and test where the tables to be merged need a join

I'm writing a stored procedure that should sync a table from our production environment to our test environment (once a day). I have 2 tables. To make it easy lets call them Meters and Measurements. Meters = [Meter_id, Location] Measurements = [Meter_id, Value, MeasurementTime] I want to keep Measurements in sync and lets assume that...

SQL Server 2005 replication of DBs cross-server -- need to know when a row was inserted/updated on the target server

I am BI Manager on top of a SAP installation. I have a SAP DB which the SAP application writes data to. In order to get an environment to query without loading on the sap, I have mirrored the SAP DB on a server, and it works fine. Each night I do a full load of data, and it works fine for now. I know that somewhere down the line, I will...

Access SQL database from Android?

I understand that to access a SQL database from Android I need to create a web service that will run on the SQL server and will process requests from the Android application, what I need to know is how to create this web service and how to access it from Android. If anyone can point me in the right direction then this would be greatly ap...

DataSet returns error "Must declare the scalar variable ..."

I'm trying to add a query to my dataset and getting an error "Must declare the scalar variable @searchstr". I find this a little odd because I've used the @variable to pass parameters before no problem, but for whatever reason it fails here. select DISTINCT g.groupname, CASE WHEN s.siteguid = @searchstr THEN 1 ELSE 0 END AS doesitexis...

Fetch record from a table on date difference

I have data like this. Following is the sample data. I want to get all those CustomerIDs which has date diff of 2 hours in DateCreated of Enquiry. For example CustomerId 10602 has 3 enquiries . If the time difference is 2 hours in any of these three enquiries then this CustomerId should be in my result set. Same for the other Custome...

Creating XSDs in Bulk

I have about 45 XML data files and I need to create XSDs for them. I have Visual Studio 2008 installed. What I am doing right now is opening up each XML file and creating the XSD from the menu option and then saving the XSD. Is there a command line option for me to create all XSDs? If not, is there a bulk XSD generation tool that can ...

SQL Query Retrieving Latest Row When Other Columns Are Equal

Hello, I'm having trouble figuring out the SQL statement to retrieve a specific set of data. Where all columns are equal except the last update date, I want the most recent. For example. Book Author Update John Foo 1/21/2010 John Foo 1/22/2010 Fred Foo2 1/21/2010 Fred Foo2 1/22/2010 What's the quer...

What do you call your US States table?

Silly question for the masses: Assume you have a table that handles the state of your object as it passes through your workflow. Now assume you have a standard United States State table... What do you call your US State table, without being redundant? Additional Constraint - You can't pluralize your tables. Some thoughts: UnitedStat...