sql

Move Child Rows to new Parent FK ID ?

SQL Server 2008. I have a parent row with pk id 1. While blocking all other DB users (this is a cleanup operation so resource contention is not an issue), I would like to insert a new row, then take all of the child rows and change their fk column to the new row. With the below DDL for example, I would like to insert a new row and give ...

Hidden column significance in table?

Possible Duplicates: metadata for determining unsed columns How can you tell which columns are unused in ALL_TAB_COLS? Hi, I have to fetch only used column names from all_tab_cols only not unsused ,may i know hidden_column column is marked 'Y' for unused_column only or their some other reasons also. ...

Searching MySQL fields with similar fieldnames

Hi. New to mysql and php, so forgive any obvious stupidity, please! One of mysql tables has category fields, indexed from a table of categories. Each of the categories is named category_1, category_2, category_3, etc. I'm assuming that can't I use a wildcard to search these categories, like: 'SELECT * FROM products_table WHERE cat...

SQL INSERT system date into table

Hi, I have created a table called "myTable" with a column called CURRENT_DATE and it's data type is "DATE". When I programatically update my table, I also want to place a timestamp or system date in the CURRENT_DATE field. A portion of what I am doing is shown below, but it is not working. I would think this would be easy, but... Can yo...

I am stuck in connecting SQL Server.. please help

I am doing a project of web application. I am still a beginner and have certain query. please let know what all steps i need to take up.. Whether SQL SERVER 2005 can be used with Visual studio 2008? I have the above mentioned software's installed. I installed Visual studio 2008 professional edition and which atuomatically installed Sql...

if clause in mysql

i want a simple example of if clause in mysql. i don't want to consider else case,only if clause ...

Create an HTML table like this one

Hello guys, i posted a question a while ago and i got my answer but now i kind of want a followup to this problem so i have a table like the one in the picture but i want to add total to each row or in fact a group how can i do that. This is the php code to create this table how to edit it to add the total. $sql = mysql_query( "SELECT...

What's wrong with this MySQL query?

Sorry because this is a noob question. I'm new with MySQL: I wrote a query like this: SELECT u.userid, u.alias, g.company_name, v.endtime - v.begintime AS duration, u.status, u.service_starttime, u.service_expiretime, v.begintime, u.email FROM company_users c, company_groups g INNER JOIN user_info u INNER JOIN vfon_l...

Help with TSQL query.

I'm using SQL-Server 2005 Standard. I have Users table with following columns: userID(int), userImage(varchar), userText(varchar), userLastVisit(smalldatetime), isActivated (bit), userHobby1 (bit), ..... userHobby10 (bit) userCharacteristic1 (bit), ..... userCharacteristic10 (bit) I did 6 queries to select users that haven't been o...

JOIN three tables

I am trying to retrieve two sets of information (the red and blue portions of the diagram in the one query. I thought I could do it using the sql as stated below but it does not return me anything when TableC has no records. If TableC has no records, I would still want this query to return me the results as indicated by the BLUE area. ...

C# SqlDataAdapter.Update()

Hi Anyone, Im going crazy with this. I did the ff: Create a datatable. Fill it from a SQL db thru SqlDataAdapter. Edit the datatable thru datagridview. Call the sqldataadapter.update but the changes are not persisted to the db. A closer look at the datatable after editing, the row states were not updated even if i actually edited th...

What's wrong with this T-SQL ?

What's wrong with this T-SQL : DECLARE @temp TABLE(ID INT IDENTITY,[Value] VARCHAR(100)) SET @temp = dbo.[fnCSVToTable](',2,3') ...

Any optimization Idea for this SQL (mySQL)?

I know the best way would be not to have any sql inside other sql, specially a complicated one, and would be better to use the analysis after the query, but because the way the system is build I would preffer to do it only on one query Here is the query in question ("is a really cool query") SELECT DISTINCT o.orders_id, o.faltantes...

Serialize/deserialize DataSet (as a way to backup my data)

Hi all, I have written the contents of a table in my database to the disk using the following function. private static Stream GetTableAsBinary(string table, OleDbConnection oleDbConnection) { var oleDbDataAdapter = new OleDbDataAdapter(string.Format("select * from {0}", table), oleDbConnection); var dataSet = new DataSet(); ...

showing non aggregate column in a group by query in SQL

Hello all i have a table in SQL 2008 as ID Items 1 A 1 B 2 C 3 D 3 B i would like to get the result as ID Items 1 A,B 2 C 3 B,D I have used cursors but it has considerably slowed the process , can i achieve the above result using group by query or through any other way. Thanks and R...

Paging & sorting with an existing stored procedure

I have a legacy stored procedure that returns a large resultset. The problem is that the resultset is too large to get all at once and then do paging and sorting on the web side. Without changing the stored procedure is it possible to wrap it in some other sql code to get only certain results back in a fast manner. Something like: EX...

Database: SUBSTRING upto first occurence of character

hi i have string type abc_01, abcd_01 or 02 now i want the substring upto _ ie abc_,abcd_ etc. I am using db2 as400 .Please suggest the processing through RIGHT or LEFT function ...

Is there anyway of converting c# function to sql server stored procedure?

Hi, I have a stored procedure which is written in c#: SqlConnection scn = new SqlConnection("context connection=true;"); SqlCommand scm = new SqlCommand("Select * from EPMS_Filters",scn); SqlDataAdapter sda = new SqlDataAdapter(scm); DataSet ds = new DataSet(); //template for select Query. Stri...

How do I efficiently inverse a many-to-many SQL query?

Hi everyone, I have a many-to-many relationship, in which I query all M which have a specific N, for example: SELECT M.* FROM M INNER JOIN ManyToManyTable ON M.Id = ManyToManyTable.M WHERE ManyToManyTable.N = @Id Or: SELECT M.* FROM M INNER JOIN ManyToManyTable ON M.Id = ManyToManyTable.M INNER JOIN N ON N.Id = ManyToManyTable.N WHE...

How to get Result from database by order the condition put in "IN" clause?

Sorry for bad english. bfproduct is a table and productid is primary key in this table and productname is another field defined in this table. When i execute this query, select * from bfproduct where productid in (23,5,54,3132,32). The result is as follows: productid | productname 5 15 Park Avenue 23 Good Boy Bad Bo...