sql-server-2005

Problem with importing an mdf created with SQL Server Express 2008 into SQL Server 2005

The question is probably extremely easy to resolve, but I need to resolve it because I need to carry on with my project. I am using SQL Server Express 2008 at home, and I've been working on an ASP.NET MVC app that stores my DB in an mdf file in the project's folder. The problem is that the SQL Server in the Uni labs is SQL Server 2005, a...

How to get size of file uploaded to SQL-Server?

Is there a way to tell how to get a file size that is uploaded to database? SELECT [ID] ,[File] FROM [dbo].[Reports] I would like to be able to tell user the size of File which is VarBinary(max) field in MS SQL 2005/2008. How to do that? Maybe the only way to do is to create another column and when inserting file i should al...

How to check for mutual existence of Fields in same table in Two columns

I tried using "Exist" and "IN". Not only did I not succeed, it didn't seem as an efficient solution. Here is a simplified example: TblMyTable UserName1  -  Grade  -  UserName2  -  Grade I need a query where there is a mutual relation / existence. What I mean is that the returned result from the query will only include the users wh...

How to store the file in the database ?

How to store the file which is uploaded by the user to the database ? I want to store the file in the database how can we do that ? In the back-end I am using sql with c#.net application. ...

Error while configuring Sql server 2005 for full text search

I am trying to index a table for full text search in a SQL server 2005. When I select the change tracking as Automatic and click on the next button, I get the following error TITLE: Microsoft SQL Server This wizard will close because it encountered the following error: For help, click: http://go.microsoft.com/fwlink?P...

hide columns in crystal report at run time?

how to hide columns in crystal report at run time? thanks for any suggistions. ...

case in group by in a store procedure

is possible do a case in a group by? similar to this: select * from table GROUP BY CASE WHEN @Attivita=0 THEN (RANK() OVER (GROUP BY Nome,AccountID,Matricola DESC)) END thanks ...

SQL server 2005, syntax error

This line do not work: (the problem is in the last line) SELECT Book_Name FROM Books WHERE (Year, Faculty) = (SELECT Year, Faculty FROM Books WHERE Book_Id = 1112); How can I fix it? ...

SQL Server trigger that rounds values

I need to write a trigger that rounds a value whenever it is inserted/updated into a table ...

Best method to search hierarchical data

I'm looking at building a facility which allows querying for data with hierarchical filtering. I have a few ideas how I'm going to go about it but was wondering if there are any recommendations or suggestions that might be more efficient. As an example imagine that a user is searching for a job. The job areas would be as follows. 1: Sc...

How to virtually delete data from multiple tables that are linked by a foreign key ?

I am using Sql Server 2005 This is a part of my database diagram. I want to perform deletion on my database which will start from tblDomain up tp tblSubTopics. Consider that each table has IsDeleted column which has to be marked true if request was made to delete data. But that data shoud remain their physically. Tables which will ...

Getting average from 3 columns in SQL Server

I have table with 3 columns(smallint) in SQL Server 2005. Table Ratings ratin1 smallint, ratin2 smallint ratin3 smallint These columns can have values from 0 to 5 How to select average value of these fields, but only compare fields where value is greater then 0. So if column values are 1,3,5 - average had to be 3 if values are 0,3,...

How to control order of assignment for new identity column in SQL Server?

I have a table with CreateDate datetime field default(getdate()) that does not have any identity column. I would like to add identity(1,1) field that would reflect same order of existing records as CreateDate field (order by would give same results). How can I do that ? I guess if I create clustered key on CreateDate field and then add...

Performance improvement to a big if clause in SQL Server function

I am maintaining a function in SQL Server 2005, that based on an integer input parameter needs to call different functions e.g. IF @rule_id = 1 -- execute function 1 ELSE IF @rule_id = 2 -- execute function 2 ELSE IF @rule_id = 3 ... etc The problem is that there are a fair few rules (about 100), and although the above is fai...

rename columnName and change column's data type in a table by using ADO.NET

Hello, how can I by using Ado.net rename existing column in a table and changing a column's data type? ...

Get mutually and non mutually existening Fields in same table in Two columns

This is a question similar to another question I posted here but is a little different. I am trying to get a list of all instances of mutual and non-mutual existing Users. What I mean is that the returned result from the query will return a list of users along with their co-worker. It is similar to the question here, but the differenc...

Code Alignment In SQL Server 2005

I am using SQL Server Management Studio. I want to know the shortcuts for easily aligning the T-SQL Queries and codes in a beautiful format for easy readability and understandability. Please Let me know how to align the code without using any SQL Server formatting / aligning tools. Please do give your valuable tips to align the same, ...

SQL Server 2005-data count

hi i created project using asp.net and sql server 2005.I created table and inserted datainto sqlserver 2005. but i dont how to find the(count) number of records stored in the table.how to find this? ...

Tentative date casting in tsql

I am looking for something like TRYCAST in TSQL or an equivalent method / hack. In my case I am extracting some date data from an xml column. The following query throws "Arithmetic overflow error converting expression to data type datetime." if the piece of data found in the xml cannot be converted to datetime (in this specific case, ...

check for null date in CASE statement, where have I gone wrong?

Hello, My source table looks like this Id StartDate 1 (null) 2 12/12/2009 3 10/10/2009 I want to create a select statement, that selects the above, but also has an additional column to display a varchar if the date is not null such as : Id StartDate StartDateStatus 1 (null) Awaiting 2 12/12...