Questions for sql


8154

“Violation of PRIMARY KEY constraint” when Inserting

I'm getting the above error when running an insert into on one of our tables.
2963

How to trim leading single quote and leading zeros from sql query

I need to compare two columns in a sql table. The data in one column has a leading single quote and may have leading zeros and the other column may have leading zeros. I need to trim the leading ze...
5391

How to declare a foreign key with an OR condition using Oracle?

I have a table (A) whose primary key is either a foreign key to table (B) or table (C).
8500

SQL Statement to get contract renewal amount by time range

I have two views. One view shows me the expiration dates of contracts of a customer. The other one is returning all the start dates of the customer's contracts. I wan't to find out the renewal amou...
6477

Adding datediff results to a new column

I can easily use the datediff function to get the results between 2 date and time values as number of hours but how do I put this into a new column beside the second date/time column with a custom ...
8473

MS SQL Update Query - Update all rows with that have the same field A to the top A value

this should be easy, but I'm just not getting it. I have a temp table that I'm populating from different sources. In the temp table, I have a bunch of rows that might have the same subdivision na...
4187

How to choose returned column name in a SELECT FOR XML query?

MS SQL has a convenient workaround for concatenating a column value from multiple rows into one value:
666

Using SQL, how do I update rows, using their own values?

I have the following table which I'll call 'example'
598

Removing tables with a join in SQL Server

I'm new to this DBA thing and I've been tasked with removing duplicates from a couple of tables. I'm working in SQL Server. They all have a field called LAST_UPD that tracks their last update. A...
5723

ASP.NET Connection to DB forcibly closed when importing data into table

I am using C# Visual Studio 2005 and SQL Server 2005.
2564

Get distinct records with counts

I have a table with personid and msg colums.
2846

HQL Join - Path expected for join! hibernate

I am new to hibernate and I met a following problem:
5329

Difference between these joins

Is there any difference between
3772

Convert SQL DateTime format

How can I display a DATETIME value (2010-12-02 15:20:17.000) as 02/12-2010 15:20?
3653

Looking for an embeddable SQL beautifier or reformatter

I am looking for a Java open source beautifier or reformatter for SQL that I can use to clean up DDL statements that I am generating with openArchitectureWare.
589

How to overcome an odd error when converting a BigInt to a DateTime in SQL

I have what I thought was going to be a simple cast/convert, but i am getting an odd error.
8468

Should I use flat tables or a normalized database?

I have a web application that I am currently working on that uses a MySQL database for the back-end, and I need to know what is better for my situation before I continue any further.
9575

SQL query to get neighbours from table with two dimensional data

I have a table, that contains partitioning of world map. Partition is done by splitting all area into rectangles, called 'tile'. As usual, rectangle has bottom-left and upper-right corners, both re...
918

Inserting variables into SQL query for node-mysql

In the wiki for node-mysql, I noticed that variables (kind of) were inserted into the SQL query in 2 different ways, one is by inserting a variable in the middle of the query string, and the other ...
9840

How to CREATE a 'VIEW(SQL)' in CodeIgniter and SELECT data from it?

I have a query that needs to check whether the record is still active before it includes it in the query. Now my problem is that the record status of that record is in another database and WE all k...
7538

Database design and hosting solution

I'm trying to prepare to build a database driven .net application and I have hit a roadblock early on due to my lack of knowledge on this topic. Searching around didn't yield anything so here I am ...
1353

MySQL INSERT … SET … ON DUPLICATE KEY failing… puzzled

Can anyone tell me what's wrong with this query:
5846

subqueries throwing an error

I have the following subqueries, and they are throwing an error
4765

SQL Insert Into a MAX value

In SQL how would I insert into a MAX count of another column
298

Referencing a composite primary key

I have two tables, with each table having a composite primary key.
5015

SQL Server Insert query for a forum

Considering a forum table and many users simultaneously inserting messages into it, how safe is this transaction?
8844

Hash a password with SHA1 in java

I want to insert a password to my database using SHA1 hash
4750

formatting sql server PRINT messages?

I have the following Print statement which print some details but it is not tabbed properly and looks awful. is there any way i could print them in tabbed format so they all meet at the same place ...
4985

SQL Query to Move Rows to Columns in a table, plus aliases

I'm trying to get data from one database and put it in the format of a second database, where the schemas are different. I'm trying to get data that is in multiple rows of one table into a single ...
916

Linq to SQL: How do I stop the auto generated object name from being renamed?

In visual studio 2008, when I drag a database table into my dbml screen, any tables that end with the letter s automatcially get the s removed from the dbml object. Is there any way to disable thi...
4968

Castle/ Active Records: How do you count objects?

I'm trying to do a simple "Select Count(*) from PRODUCTS where date > xxx" with Castle on NHibernate.
572

Can i delete an entry on multiple tables in one SQL query?

I have 5 tables in my database : Category1 , Category2 , Category3 , Category4 , Category5
3468
5621

Mysql Query to Calculate Total Products Sold by SKU

I haven't found a similar table structure in existing questions yet so I'm hoping someone may be able to help.
7601

Finding total number of rows of tables across multiple databases

I have 67 different databases and each database has more than one common table. One such table is company and I want to find total rows in that table from all the databases. How can I write a query...
1104

How to use values retured from mysql stored function with in() function?

I have a field named 'dealBusinessLocations' (in a table 'dp_deals') which contain some ids of another table(dp_business_locations) in comma separated format.
3392

Access Subform Source object

What I am trying to achieve is for a combo box (Combo_sf) selection to dictate the form in the subform control (sf_record) I have about 10 forms, their names are in the combo box data. I am new to ...
8863

Learning SQL: UNION or JOIN?

Forgive me if this seems like common sense as I am still learning how to split my data between multiple tables.
8851

sql error: Conversion failed when converting the nvarchar

I am trying to run this query but is not working. I am getting an error. How to fix?:
7850

Error inserting new rows (foreign key issue) in SQL

I am trying to debug some classic ASP code and the app keeps breaking on an insert statement. The backend is in SQL
804

Bulk Insert Data Type Mismatch in datetime

In My Bulk Insert Query i have one of the column in .LST file as |12083121022612| Format of this column is as "YYMMDDHHMMSSTT" In dbo.ReportMain Table i have set Data Type for this as datetime
603

using jquery to write sql queries?

how to use jquery to write sql queries. consider a webservice call using jquery to asp.net webservice, sending an sql query and getting back the results in json format. but there's a problem with the
4308

C# - closing Sql objects best practice

If you have a C# function with Sqlaccess, is it mandatory to close all objects/handles, or is everything cleaned up automatically once you exit the function
3043

In SQL how to compare date values?

Using MySQL syntax and having a table with a row like:
8572

Create a table in Oracle using the boolean value (true) as an unique index field

Imagine a table CARD_SERVICE with KEY(Id_number, Begin_date, Service_Type), End_date and Is_active.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.