sql

SQL Server - update only when values are different

Hi folks, In SQL Server 2008, how do I update fields in a table only if their values differ with the values in the update statement ? For example: I have TableA with column FirstName whose value is 'Roger Moore' with an unique id of '007'. Now, i am calling an update statement but it should update the 'FirstName' field only if value...

More efficient left join of big table

Hello, I have the following (simplified) query select P.peopleID, P.peopleName, ED.DataNumber from peopleTable P left outer join ( select PE.peopleID, PE.DataNumber from formElements FE inner join peopleExtra PE on PE.ElementID = FE.FormElementID where FE.FormComponentID = 42 ) ED on ED....

View all functions from the Sql Database?

How can i view all the functions (build in) in sql database using sql management studio? ...

How to see contents of deployed datasource?

I've inherited a project (without a handy handover) that contains reports published to a Reporting Server (2005). MY SSRS knowledge is 4 years stale, so I need your help. I need to edit one of the published reports, is this possible? I also want to peek into the Data Source on the RS, coz that's probably where I can change stuff. I'll...

Can I add a delay to sql server transactional replication ?

I've got transactional replication configured from a database called DBProd to another database called DBWarehouse ; everything works fine, and transaction are usually replicated instantaneously to the warehouse .... which is my problem. I'd like to add a slight delay to the replication (something like 10 minutes), so that the replicate...

Social Networking & Network Affiliations

Hi. I am in the process of planning a database for a social networking project and stumbled upon this url which is a (crude) reverse engineered guess at facebook's schema: http://www.flickr.com/photos/ikhnaton2/533233247/ What is of interest to me is the notion of "Affiliations" and I am trying to fully understand how they work, ...

Finding Shared Columns in SQL Server

Is there a quick query I can run that returns all columns of the same name between two tables? I have many pairs of tables that I know are tied together, but I'm not sure which of the 50 or so columns they have in common. ...

postgresql syntax while exists loop

I'm working at function from Joe Celkos book - Trees and Hierarchies in SQL for Smarties I'm trying to delete a subtree from an adjacency list but part my function is not working yet. WHILE EXISTS –– mark leaf nodes (SELECT * FROM OrgChart WHERE boss_emp_nbr = −99999 AND emp_nbr > −99999) LOOP –– get list of next...

How to parse a date from an SSIS Excel filename

I want to use the foreach container to iterate through a folder matching something like: "Filename_MMYYYY.xls". That's easy enough to do; but I can't seem to find a way to parse the MMYYYY from the filename and add it to a variable (or something) that i can use as a lookup field for my DimDate table. It seems possible with a flat file ...

SQL - Counting sets of Field-B values for each Field-A value

Hello, First of all sorry that I could not think of a more descriptive title. What I want to do is the following using only SQL: I have some lists of strings, list1, list2 and list3. I have a dataset that contains two interesting columns, A and B. Column A contains a TransactionID and column B contains an ItemID. Naturally, there ca...

Table Variables in SSIS

In one SQL Task can I create a table variable DELCARE @TableVar TABLE (...) Then in another SQL Task or DataSource destination and select or insert into the table variable? The other option I have considered is using a Temp Table. CREATE TABLE #TempTable (...) I would prefer to use Table Variable so that it remains in memory. But ...

What are the advantages of a query using a derived table(s) over a query not using them?

I know how derived tables are used, but I still can’t really see any real advantages of using them. For example, in the following article http://techahead.wordpress.com/2007/10/01/sql-derived-tables/ the author tried to show benefits of a query using derived table over a query without one with an example, where we want to generate a re...

Is derived table executed once or three times?

Every time you make use of a derived table, that query is going to be executed. When using a CTE, that result set is pulled back once and only once within a single query. Does the quote suggest that the following query will cause derived table to be executed three times ( once for each aggregate function’s call ): SELECT AVG...

Writing queries that are selecting different time zones

Hello, please can someone help me? I'm writing a query for a report to show different results in the factory from the machines. There is speed, efficiency and downtime. The speed and efficiency columns are recorded hourly and the downtime is recorded as and when downtime occurs. This is the code I have to collect the speed and effici...

SQL Server union selects built dynamically from list of words

I need to count occurrence of a list of words across all records in a given table. If I only had 1 word, I could do this: select count(id) as NumRecs where essay like '%word%' But my list could be hundreds or thousands of words, and I don't want to create hundreds or thousands of sql requests serially; that seems silly. I had a though...

SQL SELECT Statement

I have a table with the following columns: id, teamA_id, teamB_id Will it be possible to write a SELECT statement that gives both teamA_id and teamB_id in the same column? EDIT: Consider this example From id, teamA_id, teamB_id 1, 21, 45 2, 34, 67 I need Teams 21 45 34 67 ...

MySQL SELECT Statment to return 2 coloumns into 1

Hi, I have a table with the following columns id, teamA_id, teamB_id Will it be possible to do a MYSQL SELECT statement that gives both teamA_id and teamB_id in the same column? EDIT Consider this example From id, teamA_id, teamB_id 1, 21, 45 2, 34, 67 I need Teams 21 45 34 67 ...

Can you modify SQL DB schema in a transaction to know if all changes were applied?

As part of my (new) database version control methodology, I'm writing a "change script" and want the change script to insert a new row into the SchemaChangeLog table if the script is executed successfully, or to reverse changes if any single change in the script fails. Is it possible to do schema changes in a transaction and only if it ...

Is there a way to select nth column in a SELECT clause from a table/view

I've this GIGANTIC view with several hundred columns and I need to select 114th column something like: SELECT "144" FROM MyView; PS: Obviously, I don't know the name of the column. I just copied the results row into an Excel file, searched for a particular value that is in EJ column so I want to select all rows showing only nth column...

Will these security functions be enough? (PHP)

I am trying to secure my site so I don't have sql injections and xss scripting. Here's my code. //here's the from, for brevity, i just show a field for users to put firstname <form> <label for="first_name" class="styled">First Name:</label> <input type="text" id="first_name" name="first_name" value="<?php if (!empty($first_name)) echo ...