sql-server

Why does the parameterized version of this query run slower than a non-parameterized version?

Sample Query: CREATE PROCEDURE dbo.Test (@p varchar(10)) AS DECLARE @param varchar(10) SET @param = @p + '%' SELECT * FROM table1 t1 INNER JOIN table2 t2 on t1.id = tr.id WHERE t2.desc LIKE @param I've a query which is similar to one above and when i use this in stored procedure it runs indefinitely without giving any output. But if ...

How do I split a sentence in SQL Server 2005

I have a column named Address in a table. I have values such as 12-15 Hardley Street 2A-C Hardley Street A-2c Hardley Street A-B Hardley Street I am required to keep the hyphen(-) intact in the first three rows. i.e. If there is a number in the word that contains the hyphen(-), I should keep it, else I should replace with...

How to get an element tag in sql server

Hi everyone I have a store proc that receives some xml like this: XML 1 <Root> <pickh attribute1="897" attribute2="GGG" ....> <pickd attribute1="123" attribute2="678" ..../> </pickh> </Root> XML 2 <Root> <rcpth attribute1="ABC" attribute2 ="DEF" ....> <rcptd attribute1="012" attribute2="345" ..../> </rcpth> </R...

UnhandledReportRenderingException in SQL Reporting Service happening randomly

Hi: one of our customers are having this exception randomly. We put in some re-try code and keep-alive code, yet it still happens. So I am looking at the SQL log our customer sent us. And I saw this. So basicaly, one of the report has no data in certain field. would that be the cause of that problem? library!ReportServer_0-15!150c!10/...

working with images as a database table column

Hi, Ii have a database (sql server 2008) and I am working with c# in visual studio 2010. I want to establish a connection with my db. I have written a code for that as follows: SqlConnection mySqlConnection = new SqlConnection ("Data Source=servername\\SQL2008; Initial Catalog=MyData;UID=MyID;PWD=mypassword;"); SqlCommand...

SQL - How to backup a database and export as a MDF file with MS SQL 2008 R2

Hello all, I have created a database "test" with some tables in MS SQL Server 2008 R2 (i.e. MS SQL Server Management Studio). Now, I need to export this database as a MDF file. What should I do? Thank you ...

Select most recent rows based on a DateTime field within 5 mins of current time.

In a SQL Server table, I have a DateTime field and every time I have a login failure for an external web service I write the current DateTime to the table. I currently have code that parses through the returns and determines if there are > 2 failures within 5 mins. If so I have a flag to turn off calling of the web service. I am curious...

Best way to move data between tables and generate mapping of old to new identity values

I need to merge data from 2 tables into a third (all having the same schema) and generate a mapping of old identity values to new ones. The obvious approach is to loop through the source tables using a cursor, inserting the old and new identity values along the way. Is there a better (possibly set-oriented) way to do this? UPDATE: One a...

get list of numbers in between two columns

I have a table1(startnumber, endnumber) in oracle; Now I need to select all the numbers lies in between startnumber and endnumber from table1 data eg. table1 startnumber endnumber 10 15 18 22 34 50 Now I need the result set as: 10,11,12,13,14,15,18,19,20,21,22,...

Exclude results from join where duplicate keys match occur

I work with data that comes from multiple sources that I have no control over. These sources tend to have duplicates in the "key" values. I need to keep any of these duplicate values form matching in a join. Using the following data T1 | ID | FirstKey | SecondKey | ThirdKey | AdditionalColumns | +----+----------+-----------+-------...

SQL Server - can I load MDF without LDF file without losing data?

Hello all, I have a backup database file (i.e. test.mdf), however, I don't have the LDF file. I was told that SQL Server 2008 R2 can load MDF without LDF. Is that true? Thank you ...

Excluding matches on JOIN fields that are NULL

If you do a join that looks like this SELECT T1.KeyField1, T1.KeyField2, T2.Field3 FROM T1 JOIN T2 ON T1.KeyField1 = T2.KeyField1 AND T1.KeyField2 = T2.KeyField2 Is there a way to not allow NULLS to match similar to the results this query would return SELECT T1.KeyField1, T1.KeyField2, T2.Field3 FROM T1 JOIN T2 ON T1.KeyField1 = T2....

SQL Server 2005 backups for previous 5 days on disk?

My goal is simple. I want to have SQL Server keep a nightly backup of a DB for a rolling 5 days. So each night at some time I want a new DB backup made and one deleted such that I have a rolling 5 days on disk. I am trying to get a maintenance plan set up to handle this work and have the saving of the file done (I think). I have the ba...

File upload Date add in table and display on grid.

Hello, I have table called tblfiles. I've added loaddate column here. I am uploading file to table using button click code. I want to add date in table automatically like system date and display on my grid. I am not entering date here, I need get automatically in table and display on grid. I am using C# .NET and SQL Server 2005. Here'...

SQL Server: How to convert a result of a query into two columns: Field Name and Value

HI, now I have a simple question. This is a simple scenary: I have a Table "Table1" with three fields (a1, a2, a3). The result of query is a simple row but I need to create this kind of query: SELECT 'a1' as [Field], a1 as [Value] FROM Table1 UNION SELECT 'a2' as [Field], a2 as [Value] FROM Table1 UNION SELECT 'a3'...

Creating a one-to-one mapping in Sql server 2008 and Entity Framework 4

I have two tables, Customer and CustomerConfiguration that should have a one-to-one mapping. What I did was make customerId the primary key (and identity) for Customer, and then created a customerId field in CustomerConfiguration that is unique and is mapped to the Customer.customerId. So this seems to give me what I need, and EF4 pick...

Sql server 2008 - performance tuning features for insert large amount of data.

Hi, I have to insert large amount of data into a table. Does sqlserver 2008(compared to 2005) has any new features to increase the performance in this case ? ...

Has date type changed in SQL Server 2008?

I am confused reading statements in "Why is 1899-12-30 the zero date in Access / SQL Server instead of 12/31?" Was there date type in SQL Server before 2008 version? I cannot find. In SQL Server 2008 zero date is 0001-01-01. Were there any date type before (in previous SQL Server versions) how is it backward compatible? ...

please any one provide sql server 2005 BIDS software to install in my pc

please any one provide sql server 2005 BIDS software to install in my pc. is there any free download for this software . really its urgent for me please any one help me ...

How to set variable from a SQL query?

Hi, I'm trying to set a variable from a SQL query: declare @ModelID uniqueidentifer Select @ModelID = select modelid from models where areaid = 'South Coast' Obviously I'm not doing this right as it doesn't work. Can somebody suggest a solution? Thanks! ...