sql-server-2005

What represents a double in sql server?

I have a couple of properties in c# which are doubles and I want to store these in a table in sql server, but noticed there is no double type, so what is best to use, decimal or float? This will store latitude and longitude values, so I need the most accurate precision. Thanks for the responses so far. ...

A query taking a lot of time to execute nearly 2 minutes 10 seconds Please help me to make this query fast

The total Numbers of record in table gym_membercommon are 40352. The total numbers of records for tenant 3 is 10250. In the table gym_membercommon i need to find all the duplicate records that have any of the number common within that tenant. create table #temp ( meco_Commonid int, meco_ten...

Function in SQL Select Statement

CREATE VIEW View1 AS SELECT Col1, Col2, dbo.fn1(col2) as Col3 FROM TestTable /* --Instead of writing below query I created a new View View2 SELECT Col1, Col2, dbo.fn1(col2) as Col3 dbo.fn2(dbo.fn1(col2)) as Col4 FROM TestTable */ CREATE VIEW View2 AS SELECT Col1, ...

How can I change a column's data type and then perform actions against that new type in the same script in SQL Server?

I have a script with an Alter Column statement that's changing the data type from a Bigint to a Varchar. Immediately afterwards, I need to call Substring() on that column. Unfortunately, the syntax checker of SQL Server won't let me do this. I need to add a 'GO' statement to split the commands. The problem with this is, I also need to i...

SQL Server 2005/2008: Insert a File in an varbinary(max) column in Transact-SQL.

Is it possible to insert a file in a varbinary(max) column in Transact-SQL? If yes, I would be very please to have a code snippet to at least give me an idea how to do that. Thanks ...

Working with the SQL Server XML data type

I've got a table which has a XML field. The typical XML it contains is; <things> <Fruit> <imageId>39</imageId> <title>Apple</title> </Fruit> <Fruit> <imageId>55</imageId> <title>Pear</title> </Fruit> <Fruit> <imageId>76</imageId> <title>Grape</title> </Fruit> </things> In my table i've got around 50...

Most efficient way to store a 20 Meg file in a SQL Server 2005 IMAGE Column

We store documents in an SQL Server 2005 database table with a column format of "Image". Every time I try to store a PDF file which is greater than 1 Meg, it somehow gets corrupted. Is there any particularly efficient method in .NET to serialize and store large files (~10megs) into a database? [Edit] Microsoft actually says the max f...

Sql Express 2005: Restore backup to given time

Hi, I successfully deleted all records from a table in a database. I have a 18h old full backup + the transaction log. The database backup is FULL, the recovery model is SIMPLE. Is it possible to "roll back" this delete from the log? I've tried restoring this database to another name with a time before the delete event, but it keeps r...

Sql Server adding another user

I have a Database say TestDatabase.I have already added an user under NTAuthority\SYSTEM(Role) Db_owner. Again i wish to add another user to the same Database under NTAuthority\System with different role. I received the following error : The login already has an accoind under different username. SQL Server Error :15063 How can i a...

SSIS (SQL Server 2005) Does not trap SQL exception

I run an "Execute SQL Task" in SSIS It runs a stored procedure which does some validation In the Stored Procedure I have a RAISERROR command when something goes wrong. However when I test for this, this task fails to abort. I have Googled about this and found lots of references, but no solution that works for me. I have upgraded my SQL S...

Merging two tables

I have two tables with the following columns (identical columns in both tables): FunctionName, FrequencyCount I want to merge these two tables into a final table with columns: Function Name Base Frequency count Compared Frequency count Delta of Frequency count Merge operation should happen as follows: If [FunctionName] is in Ta...

How to programmatically copy a table in SQL Server, without the data?

I need to copy a table I already I have in a SQL server database, but I don't need th edata contained in the source table. The examples I found only involve copying the data. Copy the table structure only, not the data. Source and target tables are in the same database. Target table does not exist yet. Need to do this programmatically...

SQL select sum from other table as a column via junction table

I have 2 regular Tables "Tasks" and "Employees" and one junction table EmployeeTasks simplified they look like this Tasks TaskID ProjectID Duration Employee EmployeeID EmployeeName EmployeeTasks EmployeeID TaskID I am trying to find a tsql query that based on a common project ID would deliver a summary of the total time spen...

Problem with merge replicated database and updating via tableadapter

Hi, I'm maintaining an old application. I'd to start a merge replication between two servers. But afterwards I get these error messages "Updating columns with the rowguidcol property is not allowed." Is there really now way to use the tableadapters for updating anymore? Do I have to refactor this application in order to be able to do a...

SQL 2005 - Search stored procedures for text (Not all text is being searched)

The following bits of code do not seem to be searching the entire routine definition. Code block 1: select top 50 * from information_schema.routines where routine_definition like '%09/01/2008%' and specific_Name like '%NET' Code Block 2: SELECT ROUTINE_NAME, ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_DEFINI...

How to set sqlCacheDependency?

I am getting this error: Parser Error Message: An attempt to attach an auto-named database for file C:....\Database.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. This is the relvent code from web.config file: <connectionStrings> <add name="LocalSqlServer" connec...

Create a Duplicate Database - Different Collation

My main question is how to copy a whole database having a English collation to one having a Greek collation? The source database is having all the tables and the related data. I have a clean Greek collation database. I want to copy everything from source to destination. One solution that I found in a KB article, consisted of the followi...

Select query takes 3 seconds to pull 330 records. Need Optimization

Hi all, I have and normal select query that take nearly 3 seconds to execute (Select * from users). There are only 310 records in the user table. The configuration of the my production server is SQl Server Express Editon Server Configuration : Pentium 4 HT, 3 ghz , 2 GB ram Column Nam Type NULL COMMENTS Column Nam Type NULL...

SQL query help, ms sql server 2005 (group by and having)

I writing a query within ms sql server 2005 and having some trouble getting it to run. I need my query to include: Include all docs from Date Range 2009-07-20 to 2009-08-04 Include a Sum column using the 'Size' field Include a record count column Group By Name select Name, count(*) AS FileCount, SUM(Size) From alldocs Group by DirNa...

Count(*) vs Count(1)

Hi, just wondering if any of you guys use Count(1) over Count(*) and if there is a noticeable difference for SQL Server 2005 in performance? Or is this just a legacy habit that has been brought forward from days gone past? ...