sql-server

Get name tables, name columns, name datas using .net.

How to get all name tables, name columns, and values in database. Example i have database "Northwind" in sqlserver 2005. The name or value may store in collection like System.Web.UI.WebControls.Table or list collection, or other possible accessible. Example: "Customers" as name table, "CompanyName" as name columns, and "" as values in c...

Database mirroring and replication on SQL Server 2005

How can I configure my mirror database to publish its data to the same replication database that my primary has ( I need to take my primary database offline for maintenance purposes.)? ...

Good SQL search tool?

FreeTextTable is really great for searching, as it actually returns a relevancy score for each item it finds. The problem is, it doesn't support the logical operator AND, so if I have 10 items with the word 'ice' in it, but not 'cream', and vice versa, then 20 results will be returned, when in this scenario 0 should've been returned. A...

Is there a way to specify a cascading delete, on a query by query basis?

On a project I'm working on we've got some tables with numerous foreign key relationships, and because it's in early development the number of relationships will likely change. We'd like to be able to delete records from certain tables but are reluctant to set up cascading deletes on the foreign key relationships. We've considered the ...

SQL and search query calculated value

Hello... Suppose we have a table with collumns (A,B,C) We want to search this table based on a criteria that is calculated from collumn C... and other parameters Because the calculation is complex and cant be represented in sql query... what should i do? Make the filtering at application level ? ...

SQL TOTAL AND GRAND TOTAL

hEY ALL i have a table that shows transactions and their status. How can i create a column that shows the total of transactions that are completed,rejected,declined and the grand total of all on a different column for example i am looking something like this Completed 100 Rejected 50 Declined 20 Total 170 In 3 different rows...

Possible for SQL stored procedure to call .NET object?

Is it possible for a SQL Stored Procedure to call a .NET object? In my situation, I need to take a string parameter and return a hashed result that can be consumed by my secure client. I can either have this SP called on a per result basis (once per row), or I can possibly return multiple rows. It all depends on what SQL will support ...

How to backup remote SQL Server database to local drive?

I need to copy a database from a remote server to a local one. I tried to use SQL Server Management Studio but it only backup to a drive in the remote server. Some points: I do not have access to the remote server in a way that i could copy files; I do not have access to setup a UNC path to my server; Any ideas of how can I copy thi...

Retrieve DataTable info for a table in SQL Server

I need to get the column names, primary keys, foreign keys, and other schema info. The DataTable class seem to contain all of those. Below is the current code I got so far. With it I could retrieve all info except the foreign keys. I'm expecting them to be defined in DataTable.Constraints but they are not. This is my current code: ...

ASP.NET Web site spawing hundereds of Connections to SQL Server Express instance - how can I identify culprit code?

This is a quite a big, quite a badly coded ASP.NET website that I am currently tasked with maintaining. One issue that I'm not sure how to solve is that at seemingly random times, the live web site will lock up completely, page access is ok, but anything that touches the database causes the application to hang indefinitely. The cause se...

SQL Server Error "Could not open a connection to SQL Server"

Hello. I know this is a known issue. But I've tried everything I found out and I can't solve it yet. I've a .Net winforms app. It needs to connect to a SQL Server in a remote server in the same network. It works perfectlly in my machine, but it doesn't in antoher machine from my work. Both machines have Windows 7 and installed the SQL s...

Help with duplicates in output

I'm in need of some help with getting my duplicates from showing more than once in my output. SELECT accountNumber AS 'Member Number', OD.orderdetails AS 'iNum', FirstName AS 'First Name', LastName AS 'Last Name', HGP.email AS 'Email', points AS 'Points -->', '$' + CONVERT(varchar(50),(CONVERT(int,Points) * .1)) AS...

SQL: How to create view from a recursive query?

Question: I have a view which I want to derive from a recursive query. The query is of the same structure as this one here: http://forums.asp.net/t/1207101.aspx And represents a treeview as an ordered dataset. How can I create a view which does this: ;WITH Tree (ID, [NAME], PARENT_ID, Depth, Sort) AS ( SELECT ID, [NAME], PARENT_I...

Determing if stored procedure can execute based on AD login

I have a stored procedure that updates data in a table for a specific record. I have several users who will be making use of this stored procedure however I only want to them to be able to update records that are assigned to them. Each record that is to be updated by the stored procedure has a field named "UserID" which define who has c...

Convert SqlCommand to T-SQL command

I have an SqlCommand with parameters. Due to some external requirement (see PS), I need one T-SQL string instead, i.e., I need ... @parameter ... replaced by ... the-value-of-@parameter-encoded-correctly ... (e.g. O'Brien --> 'O''Brien', 02 Mar 2010 --> '20100302', 3.5 --> 3.5). I know that I could home-brew such a solution quite easil...

Is it possible to have a nvarchar(max) and a varbinar(max) fields in same table

I am using SQL Server 2008 R2. I have a table which has several fields including a nvarchar(max) field. When I try and add a new field of type varbinary(max) I get an error message: "Saving changes is not permitted. The change that you have made requires the following tables to be droped and recreated". Is it possible to have a nvarch...

Why does casting AVG(intger_column) as DECIMAL return a minimum of six decimal places?

Consider this query: WITH Scores (score) AS ( SELECT CAST(score AS INTEGER) FROM ( VALUES (0), (10), (10) ) AS Scores (score) ) SELECT AVG(CAST(score AS DECIMAL(19, 8))) AS precision_eight, AVG(CAST(score AS DECIMAL(19, 7))) AS pr...

Extremely slow Table-Valued-Function with recursive CTE inside.

Hello, I've cretaed a TVF which returns a table with parent-records from a recursive CTE here. That works excellent and the result is available directly. Now i wanted to get the child-records(they have the same FK as the current record's PK). The problem is that it takes 1:10 minutes to get 22 child-records for a given id. Why is this s...

SS Analysis Services ( SSAS ) DB schema comparison tool?

Does anyone know of a tool that compares SSAS databases? Not their data, just schema and maybe partition definitions. ...

sql date convert to string format

Hi All, How can I convert GETDATE() into a string like so: '2010-10-15' -rod. ...