sql-server

SQL Sort Order by The Order Specified In the Query

Say I have a query "select * from clauses where id in (0,2,5,1,3)" and I actually want the rows returned in the same order they are specified the where clause. The order of the IDs will change from query to query and there is no pattern to the order. I know it's possible to alter the data model, create temp tables, etc. But trust me ...

Sql Server Catalog/DB pointer --

I have a production server and I standardized the names of all the DBs on the server to projectName.whatever The problem is I have one database named projectName_logging I want to rename it to projectName.Logging (OCD a bit?) The problem is there are connection strings that all say projectName_logging. Is there a way to sa...

XDocument to dataSet, my nested nodes are getting treated as new tables?

When looping through elements it thinks the child node is a table, when it should just be a column. I have most of the code working well, until I the code gets to this part: (all of my code is at the bottom) new XElement("TBL_Magic_TripCountries", lstCountry.Items .Cast<ListItem>() ...

SQL Query to remove hyperlinks from a column

Hello, I have a column dek with the following data I like Stack Overflow site. The users and answers are good. I also like site1.com and site2.com. I want to retrun the data as follows I like Stack Overflow site. The users and answers are good. I also like site1.com and site2.com. Basically, want to remove all the hyperlinks...

Is there a tool to build a relationship tree of the stored procedures and functions used in SQL Server 2008?

I have a legacy data-driven application with an extremely complicated data model (and hundreds of SQL stored procedures and functions with no clear delineation of responsibility) in SQL Server 2008. We have both web app and reporting stored procedures and they are supposed to live side-by-side but there are examples where this rule wasn...

SQL incrementing help

1. Name---ID--- SEQ 2. *---------101--1 3. *---------101--2 4. *---------101--3 5. *---------999--1 6. *---------999--2 Iqnore the -'s What im importing is Name, ID, and other fields. What im trying to assign is SEQ. I'm not sure how to reset a count when I get to the 2nd group. Im using MS SQL Server 2005 ...

How would you implement a very wide "table"?

Let's say you're modeling an entity that has many attributes (2400+), far greater than the physical limit on a given database engine (e.g. ~1000 SQL Server). Knowing nothing about the relative importance of these data points (which ones are hot/used most often) besides the domain/candidate keys, how would you implement it? A) EAV. (boo....

LTRIM usage with SQL server 2005

I am a bit of an sql noob so please forgive. I can't seem to find a usage example of LTRIM anywhere. I have a NVARCHAR column in my table in which a number of entries have leading whitespace - I'm presuming if I run this it should do the trick: SELECT LTRIM( ColumnName) From TableName; Will this give the desired result? ...

How to check for a substring in a column, using CASE /IF (SQL querying)

I need to return one of 2 values for certain conditions: My different cases are: when one column has 'substring' on the right end, return that column. (i.e. LIKE '%substring') Else return other column (from other table) This works: SELECT * From Table1 where col1 is not null and col1 like '%substring' However, this doesn't work: ...

Is there a way to pivot a customer ID and a their most recent order dates?

I have a query that gives me all customer's and their last three order dates. EX: CustomerId DateOrdered 167 2006-09-16 01:25:38.060 167 2006-09-21 13:11:53.530 171 2006-08-31 15:19:22.543 171 2006-09-01 13:30:54.013 171 2006-09-01 13:34:36.483 178 2006-09-04 11:36:19.983 186 2006-09-05 12:50:27.153 186 2006-09-05 12:51:08.513 I want...

Best way to prevent Update

Hi All, I have a situation where we want to prevent the update of a table for a specific scenario. So for 95% of the updates I would want the update to flow through as normal and update the desired fields....for that other 5% I want to prevent the update from happening. This will be based on data passed in the update along with what i...

Serializable transaction appropriate for this scenario?

edit: SQL Server 2005 I have a customer application running on 5 separate servers. Each application is looking at a single scheduling table. I want to be sure that no machine can access the same record at the same time as any other machine. Each server is capable of processing 1 row only at a time. Basically, the application just se...

SQL Server, not inserting records in correct position after deleting one or more records

I know, is a very basic question, but I am in the process of re-learning sql stored procedures, and this is what happended: I was practicing with some simple delete / insert routines, when encountered with this: if I ONLY insert records: 1. dog 2. cat 3. t-rex 4. llama all is ok, then I call a delete procedure, passing the colum...

How to use PHP's odbc_connect() to connect to an ODBC DSN on another host on the same LAN?

I've successfully tested a connection via PHP's odbc_connect() to a SQL Server 2005 Express database on a Windows Vista box using the following code: $connect = odbc_connect("mssqllocal2", "", ""); // first arg is the System DSN that I configured on Windows This connection works fine when executed from an instance of WAMPserver on th...

SL app doesn't connect to Database from IIS, but does from VS2010 - SQL Server Auth, not Wndws Auth

I've made two small/test Silverlight apps with VS2010 (I am new to it), having same problem with both... When I run/debug it from within VS2010, the app runs and it connects to the database fine. But when I publish it to the IIS (on the same machine VS2010 is on), the app will run, but it will not connect to the database. I'm using SQL ...

SQL Server 2005 XML to table

I'm using classic asp and I'm passing in a varchar (ado data type) into an xml data column in a proc. The xml looks as follows: <DocumentCriteria> <Document documentGUID="{B49654E7-9AF2-4B89-AF8F-5146F7CD4911}" graderFYC="5907"> <criterion cnumber="1" rank="3"/> <criterion cnumber="3" rank="3"/> </Document> </Docume...

Self Join and Iterative SQL

Sample Table Emp Id Emp Name Manger Id 1001 arun 1004 1002 Bharath 1004 1003 Chitra 1004 1004 Devi 1005 1005 Eli 1006 1006 Fatima 1007 1007 Ganesh 1008 when i select manager id 1004 it should display three names arun,bharath,chitra and if i select 1005 it should display devi,arun,bharath,chitra FY...

How to use the result of a complicated query in self-join?

I'm writing a stored procedure on SQL Server 2000. I've written a complicated select statement that takes 18 seconds to run. The question is, how can I self-join the result correctly and efficiently? Is it possible to manage it in a single select statement without repeating the big query statement that I currently have? Or should I sa...

SQL CASE and local varaibles

Hi, I am studying SQL, I would like to know how can I use local variables in CASE statements in SQL. Thanks guys for your help. This script gives me error: DECLARE @Test int; DECLARE @Result char(10); SET @Test = 10; CASE @Test WHEN @Test = 10 THEN SET @Result='OK test' END Print @Result; I USE MS...

VS 2010 Database Project deploy sql scripts

Hi, I am working on a sql database project in VS 2010. I know how to synchronize the schema, but what I want is this: 1. I have some data sql scripts that inserts data into some tables. 2. I want to when I click Deploy on the DB project to automatically deploy those data scripts and execute them on the sql server. How to do this? Thank...