sql-server

What is the better way to use WPF,WCF,PRISM

hi, I'm developing an EMR Application as my project. there Im using WCF to transfer all the data from the centralized server , WPF for the UI and PRISM to build modules. I have 3 projects in my solution for WPF/PRISM application The Main project(mainApplication) where the shell and bootsrapper are. Class library(modulesLib) to hold ...

what is good, explicite cursor in backend or loop in front end?

what is good,using explicite cursor,while loop on database side OR using loop on front end (application side programm)??? Edited:- Hi,if I want to iterate and i am using ado.net asynchronous(disconnected) connection (ie.I have a datatable and i am applying for loop on datatable in front end) -- In this case,If i want to iterate which is...

How to generate a diagram of a very large database schema (SQL Server)

I have a very large database I need to diagram. The database is SQL Server 2008 on x64. It is large in that there are hundreds of related tables, each with up to 2000 fields (some are sparse), multiple relationships between tables (often hundreds per table, in fact), multiple schemas... you get the idea. I tried to use the Database Diag...

How to test performance for your database Best practice

Hi, I need to test indexes performances for some table in my database. After I run my query with indexes or without them I always use this code; SELECT * FROM sys.dm_exec_query_optimizer_info; And I receive details about my query. My problem is: using sys.dm_exec_query_optimizer The details for my query are always changing making...

I have one big query for performance related in SQL Server 2005

I have one big query for performance related in SQL Server 2005. I have data like this id parentId 1 null 2 1 3 1 4 2 5 4 6 3 I want the order for the records by downline with parentId and id wise like id Order 1 1 2 2 4 3 5 4 3 5 4 6 I don't want to use loop, because loop is creating the problem if high ...

How to get date representing the first day of a month?

I need functionality in a script that will enable me to insert dates into a table. What SQL do I need to insert a date of the format 01/08/2010 00:00:00 where the date is the first day of the current month. What do I need to change order that I can specify the month value? Thanks ...

TSQL function to find difference between two dates taking weekends and holidays into account

Tomalak posted an excellent response to an existing SO question: http://stackoverflow.com/questions/593898/sql-datediff-advanced-usage/594087#594087 It almost worked for me but I needed to compute the business hours difference between two dates, excluding weekends, even if less than a week had elapsed. My solution adds a while loop (w...

SQLCLR & IronPython

Hi, Im feeling crazy and I've decided I would really like to write a User-Defined Function in Python that would run in SQL Server 2008. I am interested in doing this as I have a few thousand lines of PL/Python functions written for PostgreSQL and I am interested to know if I can get the project running on SQL Server instead. I am looki...

Delete A Record From Two Separate SQL Data Sources

I have a slight issue with deleting a record that is stored on two separate SQL servers. I am using an ASP.NET databound control on a datagrid with delete button commandfield linked to one data source. Is there a way of deleting the same record from another data source at the same time? Any advice would be much appreciated. ...

Typed Dataset ConstraintException on insert

Basically I have a table that contains hierarchical data. So I have an id column, and a rollup column which points to the id column for each child's parent. This table is loaded from the database using GetData() on the TableAdapter then the table's primary key autoincrementseed is set using: SELECT IDENT_CURRENT('TableName') + 1 ...

Transact-SQL / Check if a name already exists

Simple question here. Context: A Transact-SQL table with an int primary key, and a name that also must be unqiue (even though it's not a primary key). Let's say: TableID INT, TableName NVARCHAR(50) I'm adding a new rows to this able through a stored procedure (and, thus, specifying TableName with a parameter). Question: What's the b...

SQL Server Performance and Update Statistics

Hi We have a site in development that when we deployed it to the client's production server, we started getting query timeouts after a couple of hours. This was with a single user testing it and on our server (which is identical in terms of Sql Server version number - 2005 SP3) we have never had the same problem. One of our senior dev...

calling one stored proc from another by executing command

In my stored procedure I have to pass a table and column name which may change everytime. So I build command and execute it. I want the output in another variable @curr_id. This store procedure will be called by second stored procedure by using @curr_id as input. My problem is populating the @curr_id vriable. It is returned as zero. If ...

Identify column-level dependencies between databases

Is there a way to identify column-level dependencies within and between databases? I'd like to generate a report of all columns in a database that are unused by anything (views, procs, UDFs). e.g. In database 'DB1', there is a table with a column called 'col1'. How do I determine if 'col1' is being used by procs, views or UDFs in eit...

SQL constraint for between multiple values

Here is my table Events Start : Datetime End : Datetime I'm trying to make sure that a new Event does not overlap any previously entered events. I'll admit my SQL knowledge is novice at best. The following is a select statement that gets me close but I can't figure out how to turn it into a constraint (would I use check?) SELECT e....

Update column with another value from the same table?

The setup is like this: Col1 Col2 12345 12 12348 14 20145 16 00541 Null 51234 22 Simplified, obviously. What I want to do is update Col2 wherever it's Null by setting it to the Col2 value for whatever has the closest value in Col1 (so in this example, row four should have Col2 set to 12). This is...

Is it possible to shrink a log file on a linked server using DBCC SHRINKFILE?

I am doing a large archival of data from one DB to another DB on a linked server. I am copying from MS sql server 2000 to MS sql server 2005. This involves copying millions of records and then deleting them. This all happens via a dynamic script. I would like to incorporate the shrinking of the log file for this process, but I am unabl...

Advanced tutorial on analytic functions in Oracle/SQLServer

Can anyone recommend a good tutorial (or book perhaps) that covers advanced topics in the use of Analytic Functions? I'm looking for something that covers both Oracle and SQLServer - or two separate guides if a single one doesn't exist. Something that offers good examples of using nontrivial functions (LAG, LEAD, GROUPING, PERCENTILE) ...

Selecting same column with different where conditions

This query returns the sum of "closed" daily sales for a particular salesperson within a particular date range: SELECT SUM(price) as closed_total FROM dbo.Sales WHERE salesperson_ID = @salesperson_ID AND date_ordered BETWEEN @start_date AND @end_date AND closed = 1 GROUP BY date_ordered The output looks like:...

If-Else Statement in T-SQL

I'm trying to alter the results of a Transact-SQL (MS SQL Server) report that is currently showing: CompanyA DVCE3 CompanyB DVCE2 CompanyC DVCE3 CompanyD NULL CompanyE DVCE3 and I would like it instead to show: CompanyA 36 CompanyB 24 CompanyC 36 CompanyD CompanyE 36 I'm sure the answer to...