sql-server-2005

How to use PIVOT in SQL Server 2005 Stored Procedure Joining Two Views

Good Morning, I have 2 views: ICCUDays which contains one record per account with fields ACCOUNT and ICCUDays, ICCUEnctrSelectedRevCatsDirCost which contains multiple records per account with fields ACCOUNT, UBCATEGORY, and DirectCost. My Goal: To create a stored procedure that outputs one record per ACCOUNT with ICCUDays and DirectC...

What is the equivalent effect to Truncating a table, when the table is referenced by a foreign-key

Straight out of the MSDN docs for Sql Server 2005: You cannot use TRUNCATE TABLE on tables that: Are referenced by a FOREIGN KEY constraint. Participate in an indexed view. Are published by using transactional replication or merge replication. I want the effect of a TRUNCATE (specifically the fact that it resets IDENTITY ...

SQL Server: How to permission schemas?

Inspired by various schema related questions I've seen... Ownership chaining allows me to GRANT EXECUTE on a stored procedure without explicit permissions on tables I use, if both stored procedure and tables are in the same schema. If we use separate schemas then I'd have to explicitly GRANT XXX on the the different-schema tables. The ...

Wrong locale in SQL Query results

I have a SQL Server 2005 database set to locale Turkish_CI_AS. The locale setting of the pc of the SQL Server is set to Turkish. Turkish decimal separator is "," and thousands separator is ".". There is a field with datatype decimal(14, 3) and it has a record with value "400,123" (that's four hundred). When I use Open Table in SQL Manage...

how can we generate auto id with .NET

i would facing a problem while working in C#. AS i have to generate an ID which is automatically when user clicks on ADD button ...

SQL Server : Getting the query raising an error

I'm using the usp_RethrowError ( given as example in Using TRY...CATCH in Transact-SQL article on technet.microsoft site ) when signaling something is wrong. Is there any way to get the query which triggers this error inside the usp_RethrowError procedure ? I would also like to add the query text to the @ErrorMessage. You can find bel...

How to update or add a column in datagridview

Using VB.NET and SQL Server 2005 In DataGridView n number of rows was displaying. Suppose I edit some value in the datagridview cell then I click save means it should update in the table also. Suppose I click add button means it should add a new row in datagridview. How to write a code for this? ...

converting date in sql server 2005

hi In my application (asp.net) I am uploading the video and storing the video in database like videoname,videotitle,dateofuploded these are the fields. My problem is when I am displaying that video I want to display the date like '2 days ago' or ' one month ago' or 'one year ago' How can I write the function for converting the date int...

Massive table in SQL 2005 database needs better performance!

Hi Guys, I am working on a data driven web application that uses a SQL 2005 (standard edition) database. One of the tables is rather large (8 million+ rows large with about 30 columns). The size of the table obviously effects the performance of the website which is selecting items from the table through stored procs. The table is index...

Count(*) vs Count(Id) in sql server 2005

I use Count function to get the total number or rows from a table... Is there any difference between the two following statements? Select Count(*) from Table and select Count(Id) from Table Is there a difference between execution times... ...

Problems creating ragged hierarchy with Analysis Services

I'm attempting to create a ragged hierarchy in SSAS 2005. The "Category Name" and "Sub-Category Name" levels should be hidden in the hierarchy if either of them is blank. Leaf nodes which always have a value must display even if these two levels are blank. An image of how the measure has been configured is as follows: I thought using...

Retrieving data from Stored Procedure which is not in a ROW [ASP.NET C#]

Hello, just wondering if how can we retrieve a data from stored procedure, who's return value is not in a row. I've run the stored procedure and it doesn't return any rows but return some data >.< just like this photo. could anyone know how to retrieve return value @rtncode in .NET? Thanks! ...

SQL Server 2005 – How to split multiple Insert into... Output Select TOP (z)...From if (Approximate) Max number of child rows in a Transaction is known.

I have these staging tables: - Order (PK=OrderID), - SubOrder(PK=SubOrderID, FK=OrderID) and - Item(PK=ItemID, FK1=SubOrderID, FK2=OrderID). I established relationships on the client (C#.NET and copied tables to staging tables in SQL Server suing SQLBulCopy). Now I need to establish Parent/Child/Grand-Child relationships on the ser...

Easy way to find out how many rows in total are stored within SQL Server Database?

I'm looking for easy way to count all rows within one SQL Server 2005/2008 database (skipping the system tables of course)? I know i could use SELECT COUNT (COLUMN) FROM TABLE and do it for each table and then add it up but would prefer some automated way? Is there one? ...

what is the difference about SCHEMA in sql server 2005 and sql server 2008?

what is the difference about SCHEMA in sql server 2005 and sql server 2008? ...

ODBC Remote connectioon problem

Hi there. I'm trying to set a connection through ODBC to an SQl Server Express 2005 instance the following connection string is working fine when I use it on the same machine Conn string: "DSN=_Vendas;TrustedSecurity = yes;"; I have an ASP.NET application that needs to use the same connection remotel, and this fails Exception: ERROR ...

How to handle encrypted column in SQL Server Database in LINQ to SQL?

Hi Guys, We are in the process of encrypting all the SSN columns (had to do it now due to security audit). We already built the DBML and now we have to change it. Can you guys let me know if there is a good way of handling this in LINQ to SQL? We use stored procedures for Insert, Update and Delete but use LINQ to SQL for all our selects...

SQL Server - join or subquery in update statements?

Is there a reason to use one of these UPDATE statements over the other with regards to performance? UPDATE myTable SET fieldx = 1 FROM myTable AS mt , myView AS mv WHERE mt.id = mv.id UPDATE myTable SET fieldx = 1 WHERE id IN ( SELECT id FROM myView ) ...

Is this query equivalent to SQL Server 2008's OPTIMIZE FOR UNKNOWN?

I'm maintaining stored procedures for SQL Server 2005 and I wish I could use a new feature in 2008 that allows the query hint: "OPTIMIZE FOR UNKNOWN" It seems as though the following query (written for SQL Server 2005) estimates the same number of rows (i.e. selectivity) as if OPTION (OPTIMIZE FOR UNKNOWN) were specified: CREATE PROCED...

SQL 2005 try/catch block never reaches 'catch' despte bogus data tests.

Hi. OK, I am not that experienced with SQL 2005 error handling and am learning my way around try/catch statements. I have written the below procedure but no matter what I pass to it, there is never any data in my ErrorLog table. I have passed all INT values, all datetime values, or data strings that are not in the DB and get '0 rows ...