sql-server

Finding the restore progress of SQL server from inside c#

I know this is most-likely a simple question but when you restore a database from inside SQL management studio you can set the update interval with stats RESTORE DATABASE [test] FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\test.bak' WITH FILE = 1, NOUNLOAD, STATS = 10 If I wanted to execute that line of...

conditional inner or outer join sql server

I would like to decide Inner or outer join ( to the same table) depending on the value. How do I do this? Thanks I have all my select values here Then bunch of joins And on the last join I would like to do CASE WHEN RTRIM(LTRIM(@AccountType)) = 'OFX' THEN INNER JOIN Subscriber.Access.SubscriberOFXAccount ASOA ON SS...

SQL Server 2000: Ideas for performing concatenation aggregation subquery

i have a query that retruns rows that i want, e.g. QuestionID QuestionTitle UpVotes DownVotes ========== ============= ======= ========= 2142075 Win32: Cre... 0 0 2232727 Win32: How... 2 0 1870139 Wondows Ae... 12 0 Now i want to have a column returned that con...

Column has a number in it, very few rows have text mixed in, can I create a new number column?

I have a table that has a column that has the cost of a product, but some (very few) rows have text mixed in the column. Would it be possible to create a new column, of a decimal type, and populate it with the other column and just ignore the rows with the 'bad' data in it? I know I can do this via code, but was hoping I could do it wi...

What is the proper way to create a recursive entity in the Entity Framework?

I'm currently using VS 2010 RC, and I'm trying to create a model that contains a recursive self-referencing entity. Currently when I import the entity from the model I get an error indicating that the parent property cannot be part of the association because it's set to 'Computed' or 'Identity', though I'm not sure why it does it that wa...

DBCC shrinkfile gives error

I am trying to shrink my log file using DBCC SHRINKFILE(db_2.ldf), which is the name for log file It gives me error every time: 8985, Level 16, State 1, Line 1 Could not locate file 'FIelD' for database db in sys.database_files. The file either does not exist, or was dropped. Can you please suggest what can I do to fix it. ...

Add date to SQL database backup filename

I'm using the below to backup a db from a SQL job. Can someone tell me how to add the current date to the output filename? Preferably in YYYYMMDD format. BACKUP DATABASE [myDB] TO  DISK = N'\\myPath\myDB.bak' WITH NOFORMAT, INIT,  NAME = N'myDB', SKIP, REWIND, NOUNLOAD,  STATS = 10 GO Thanks! ...

need help to figure out average price markup on products, I have cost and selling price

I have a database that has products in it, with both the cost and selling price. I want to create a simple report that will group similar costing, and figure out how much markup there is. I will then use this to apply the markup on new products. So my database looks like: productid, costPrice, sellingPrice 123, 9.99, 14.99 I have n...

Should I use the keyword AS when aliasing columns in SQL Server?

Simple question: Office debate about whether the keyword AS is necessary in our T-SQL statements. I've always used it in cases such as SELECT mycol AS Something FROM MYTABLE; I know you don't NEED it but is there any benefit of using it (or not using it)? I think it makes statements easier to read but people seem to disagree with me. ...

SQL Server 2008: Can I use a constraint for this?

I have a table with three fields, User, City and Country, where exactly one of the fields must be non-NULL at all times. Can I use an SQL constraint for this or should I rethink what I'm doing? The scenario is that my database should contain documents that can be attached to users, cities or countries. So a row in this table contains ex...

SSAS: distribution of measures over percentage

Hi there, I am running a SSAS cube that stores facts of HTTP requests. The is a column "Time Taken" that stores the milliseconds a particular HTTP request took. Like... RequestID Time Taken -------------------------- 1 0 2 10 3 20 4 20 5 2000 I want to provide a report ...

Transfer data from SQL Server table using query to Excel and vice-versa

I want to transfer data from SQL Server table to Excel sheet using 3 tier architecture in asp.net 3.5. After user has made required changes in the Excel sheet I want Excel sheet to get uploaded and update data in the table with validation for proper data. ...

SQL Server: Drop Table with FK

On table "A" depend about 30 other tables via FK to "A.Id". For integration testing I have to drop the table and recreate it to create a defined state. Because of the dependent objects their seem to be no way to delete and recreate the table. The error message is: Could not drop object 'dbo.A' because it is referenced by a FOREI...

pymssql connect function

i have this function pymssql.connect(host="my host",user="my user",password="my pass",database="mydb") I want to read the user and password from the user and put them there is that possible or named arguments lvalue should not be variable and if yes then how could i do that ? i.e is it possible to call this function like: pymssql,conn...

Sql Server XML-type column duplicate entry detection

In Sql Server I am using an XML type column to store a message. I do not want to store duplicate messages. I only will have a few messages per user. I am currently querying the table for these messages, converting the XML to string in my C# code. I then compare the strings with what I am about to insert. Unfortunately, Sql Server prett...

Are there generic options for version control within a database?

I have a small amount of experience using SVN on my development projects, and I have just as little experience with relational databases. I know the basic concepts like tables, and SQL statements, but I'm far from being an expert. What I'd like to know is if there are any generic version control type systems like SVN, but that work with...

Trouble connecting to SQL2005 with Windows Mobile 6

I have a windows mobile 6 device I would like to connect to a full SQL 2005 server. From the device I can ping the physical machine, but it won't find the sql server. Using cn As New SqlConnection("Data Source='myServer\sql2005';Initial Catalog=myDB;User ID=User1;password=password") cn.Open() End Using I've tested this con...

Accounting System for Winforms / SQL Server applications

If you were going to write a vertical market C# / WinForms / SQL Server application and needed an accounting "engine" for it, what software package would you chose ? By vertical market, I mean the application is intended to solve a particular set of business problems, not be a generic accounting application. Thus the value add of the pr...

sql server incorrect checksum error on deployment

When I try to start the Sql Server (SqlExpress) service I got the following message: I've looked at the log file (C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Log\ERRORLOG) and find out the following lines: 2010-03-09 06:12:35.51 spid7s Error: 824, Severity: 24, State: 2. 2010-03-09 06:12:35.51 spid7s SQL Serve...

How to use a system stored procedure in LINQ to SQL

I'd like to add the "msdb.dbo.sp_help_job" system stored procedure to a LINQ to SQL object, but I can't figure out how to specify it. If I create a new Data Connection in Server Explorer and specify the "msdb" database of the server I want, and navigate to "Stored Procedures", that procedure is not listed. Am I looking in the wrong place...