sql

customer.pk_name joining transactions.fk_name vs. customer.pk_id [serial] joining transactions.fk_id [integer]

Pawnshop Application (any RDBMS): one-to-many relationship where each customer (master) can have many transactions (detail). customer( id serial, pk_name char(30), {PATERNAL-NAME MATERNAL-NAME, FIRST-NAME MIDDLE-NAME-INITIAL} [...] ); unique index on id; unique cluster index on pk_name; transaction( fk_name char(30), tran_type char(1...

SQL for selecting only the last item from a versioned table

I have a table with the following structure: CREATE TABLE items ( id serial not null, title character varying(255), version_id integer DEFAULT 1, parent_id integer, CONSTRAINT items_pkey PRIMARY KEY (id) ) So the table contains rows that looks as so: id: 1, title: "Version 1", version_id: 1, parent_id: 1 id: 2, ti...

how to write sqlite update operation in two tables?

I am using SQLite, TABLE A ( ID FileNAME FOLDERID ) TABLE B ( FOLDERID FOLDERPATH ) I want to write a sql statement to delete all files in A where its Folder is subfolder of C:\ABC\; How Can I make it in one sqlite statement, and is it the best way to do? Many thanks! ...

SQL - First row inserted every day for the past X days

A tough SQL question (I'm using postgres by the way). I need the first row inserted every day for the past X days. one of my columns is a timestamp, which i hold the time inserted, and another column is the row id. If it's not possible to get the first row inserted every day, i at least need a unique one; a single row for every day fo...

How to save datagridview columns with datas in sql server database

Scenario is.... I have to select a row in datagridview and save those datas to database.It can any number of columns present. how to achieve this.. ...

C# DateTime Class and Datetime in database

Hello . I have the following problem. I have an object with some DateTime properties , and a Table in database that I store all that objects , in Sql server I want to store the DateTime properties in some columns of DateTime Datatype, but the format of datetime in sql server is different from the DateTime class in c# and I got an sql ex...

Automatic incremental SQL Script generation for incremental, nightly builds when using Team Build in TFS 2008 and Visual Studio 2008 ?

hi all, hope that everybody here is OK. We are using VS 2008 as development tool, TFS 2008 as version control as well as build automation. Some of our developer use dbpro for databases changes and some use SQL Server management studio. I am trying to automate build for Web Application built using C# and VB.Net. Our scenario is such tha...

How would I associate a "Note" class to 4+ classes without creating lookup table for each association.

I'm creating a project tasklist application. I have project, section, task, issue classes, and would like to use one class to be able to add simple notes to any object instance of those classes. The task, issue tables both use a standard identity field as a primary key. The section table has a two field primary key. The project table ...

Oracle query to select rows with unique code

I have a table like this C1 C2 C3 Code 1 2 3 33 1 2 3 34 2 4 1 14 1 2 3 14 i want to select only those record whose code is appearing only in single row. ie, in this case rows with code 33 and 34.. as they appear only once in this table. How can i write a query for that ...

What is an unbounded query?

Is it a query without a 'WHERE param=value' statement? Apologies for the simplicity of this one... ...

sqlite3 timestamp column

Hi I feel stupid, but I can't get a TIMESTAMP column to be shown in human understandable way in a SELECT. I could do that in MySQL, not in sqlite3. Could someone show me an example please? Thanks ...

What operation type invoked a trigger in SQL Server 2008?

I'm contemplating a single SQL trigger to handle INSERT, UPDATE and DELETE operations as part of an auditing process. Is there any statement, function or @@ variable I can interrogate to find out which operation type launched the trigger? I've seen the following pattern: declare @type char(1) if exists (select * from inserted) if ...

Getting highest results in a JOIN

I've got three tables; Auctions, Auction Bids and Users. The table structure looks something like this: Auctions: id title -- ----- 1 Auction 1 2 Auction 2 Auction Bids: id user_id auction_id bid_amt -- ------- ---------- ------- 1 1 1 200.00 2 2 1...

i need to use the sum of the value in 1 column as part of a ref in another column in a view

hi, i have a view as below. SELECT TOP (100) PERCENT 'SA' AS Doc_Type1, 'A' + SUBSTRING('000000', 1, 6 - LEN(CAST(dbo.companies.companyId AS varchar(10)))) + CAST(dbo.companies.companyId AS varchar(10)) AS Client_ID, 1200 AS Bank_Nom, 0 AS Department, CONVERT(nvarchar(20), dbo.invoices.i...

Insert into a table using a view

I have some data in a view which I want to insert into a table (same table schema) what's the easiest, cleanest way to do it. ...

How can i add '"-" in column

my query is showing in row 2000 the data of 2000-2001 & in 2001 the data of 2001-2002. how can i change the column so that it displayes column 1 column 2 2000-2001 5 2001-2002 3 2002-2003 9 2003-2004 12 . . . . and so on... ...

In SQL Server, how do I create a reference variable to a table?

I'm currently using sp_executesql to execute a T-SQL statement with a dynamic table name. However, it is really ugly to see something like: set @sql = 'UPDATE '+Table_Name+' SET ... WHERE '+someVar+' = ... AND '+someVar2' = ...' sp_executesql @sql What I would rather like to have is a TABLE variable of which is a reference to a table...

Define default value for columns in View...

I Have a View in SQL Server, in one column ( data type int64) it returns Null value! But I want to display Zero in it. How Can I define a default Value for Column in View? ...

SQL Table to another database

I have 2 databases on SQL (identical). I want a table from one database to be copied to the other database. They are both the same name and the original table can be overeritten. Cheers ...

SQL Server: invalid object name how to solve it?

error returns to me in below codes: Msg 208, Level 16, State 1, Line 1 Invalid object name 'ENG_PREP'. insert into ENG_PREP VALUES('572012-01-1,572012-01-2,572012-01-3,572013-01-1,572013-01-2', '', '500', '', 'A320 P.001-A', 'Removal of the LH Wing Safety Rope', '', '', '', '0', '', 'AF', '12-00-00-081-001', '', '', '', '', '', '...