sql-server-2005

How do I extract data from an "image" column and save it to a file?

How would I go about saving the data from an "image" column in SQL2005 to a binary file that I can use to update a row in a different database on a different server? I know that once I get the file, I can use OPENROWSET to read it in to the destination server, but I cannot figure out what the SQL is to extract the contents of the image ...

SQL - Selecting portion of a string

If I have a simple table where the data is such that the rows contains strings like: /abc/123/gyh/tgf/345/6yh/5er In SQL, how can I select out the data between the 5th and 6th slash? Every row I have is simply data inside front-slashes, and I will only want to select all of the characters between slash 5 and 6. ...

TSQL memory related queries

I need to find if /3GB switch and /PAE is enabled on a server. Also, I want to know the size of page file and physical RAM on the server. I can check them manually but how can I check them using TSQL on both SQL 2000 and SQL 2005? ...

Doing a data compare with T-SQL in a query in SQL Server 2005

Hi! Wondering if anyone knows an easy way to do this. I have a couple of tables with data, this data is "static" in that way that users don't change it, it's only me that gets to insert/update rows. And I wonder if there's an easy way to insert rows that don't exists and update rows that are different. The way that I figured would work ...

Sqlbulkcopy doesn't seem to work for me...

I have created a datatable and trying to insert that datatable through SqlBulkCopy but somehow it doesn't seem to work for me.... I got the error, The given value of type DateTime from the data source cannot be converted to type decimal of the specified target column. My Datasource is, DataTable dt = new DataTable(); dt.Columns...

Get last value based on an Id in SQL Server 2005

Consider my query, Select EmpId,RemainingBalance from Salary where EmpId='15' My results pane, 15 450.00 15 350.00 15 250.00 How to get last RemainingBalance amount (ie) 250.00... ...

Stored procedure in SQL Server (order by desc)?

I have a stored procedure that will give the latest records i.e., order by added date this is my procedure.... select distinct top 5 videos.videoid,videos.videotitle,videos.videoname, convert(varchar,videos.posteddate,106) as posteddate,videos.approvedstatus, videos.videoimage,(ISNULL(videos.views,0.0)) as [views],videos.privac...

What is wrong with this sql innerjoin?

Here is my select statement with the innerjoin of two tables, if not exists(select EmpId from SalaryDetails where EmpId in (select Emp_Id from Employee where Desig_Id=@CategoryId)) begin // some statements here end else begin SELECT e.Emp_Id, e.Identity_No, e.Emp_Name, case WHEN e....

SQL Server 2005 replication trigers - how to?

Hi, I need to run the replication of one table in SQL Server 2005. Replication should be one way. From 1 master server to many children servers. I thougt about snapshot replication, but I don't want to schedule it only for example every hour/minute ect. (I know how to do this.) but ALSO triggered it evry time new data appears in master...

How to split cell content and extract information into a new column in an SQL select statement?

I have a table where one of the columns are storing key/value pairs separated by semicolons, like this: KEY1:VALUE1;KEY2:VALUE2;KEY3:VALUE3 I would like to construct a view where I have additional columns where the value will be extracted from the field above. My question is how to extract VALUE1, VALUE2 and VALUE3 in a SELECT query....

Multiple results for one field in a joined SQL query

I'm not sure if this is possible from with a SQL query, but I'll give it a go. I'm developing a SharePoint web part in C# that connects to a SQL database and runs a query, then databinds that result set to a gridview. It's working fine, but I have a small snag. For the most part, my query will return exactly one result for every field. ...

Caching SQL execution plans

I know SQL server 2005 does some amount of execution plan caching, but would that be enough to create a difference of hours between the same query being run twice? The first time it takes 3 hours the next time it takes 1 min? Is that even possible? ...

Generating order statistics grouped by order total

Hopefully I can explain this correctly. I have a table of line orders (each line order consists of quantity of item and the price, there are other fields but I left those out.) table 'orderitems': orderid | quantity | price 1 | 1 | 1.5000 1 | 2 | 3.22 2 | 1 | 9.99 3 | 4 | 0.44 3 ...

Can I set VARCHAR size larger than 8k but less than MAX?

Starting in SQL 2005, VARCHAR(MAX) is no longer limited to 8000 bytes, it instead can go up to 2GB using "overflow" pages. But what if I want to limit this column to say, 10k bytes? It seems I get an error if I try to put anything in the size parameter above 8000. Which is odd because MAX is the same as asking for a 2GB limit. Seems ...

How do i transform rows into columns in sql server 2005

There is a question here in stackoverflow with the same title but that is not what I am looking for. I have a table like the one below Name | Count ---------------- Chery | 257 Drew | 1500 Morgon | 13 Kath | 500 Kirk | 200 Matt | 76 I need to trasform this result set into something like this Chery | Drew...

ASP.NET SqlConnection Timeout issue

Hello all, I have run into a frustrating issue which I originally thought was a connection leak but that does not seem to be the case. The secnario is this: the data access for this application is using the Enterprise Libraries (v4) from Microsoft. All data access calls are wrapped in using statements such as using (DbCommand dbC...

What is wrong in this sql select statement?

Here is my select statement, SELECT TOP 1 EmpId, RemainingAdvance FROM SalaryDetails WHERE EmpId IN (SELECT Emp_Id FROM Employee WHERE Desig_Id='27') ORDER BY CreatedDate DESC When i executed SELECT Emp_Id FROM Employee WHERE Desig_Id='27' the results were Emp_Id 16 17 But when i execute my...

table partitioning without recoding application?

In SQL Server is it possible to perform table partition without having to recode or modify the application? ...

sql server 2005 - previously quick executing stored proc run slowly until dropped and recreated

Hi, I've got a stored proc that after a period of weeks will start to run very slowly. It starts its life executing in a few seconds and ends up taking a couple of minutes to execute. We've found that dropping and recreating the procedure results in it executing in a few seconds again. The procedure itself contains a few inner joins an...

How to script sql server database diagrams in sql server 2005?

I use sql server 2005 as my database for my web application.... I generated scripts of the database by, Database->Right Click->Tasks->Generate Scripts I can script all my Tables,Stored Procedures,User Defined functions,Views,Users.... All i missed was database diagrams because there was no option for scripting it.. How to include them...