sql-server

No milliseconds value when reading DateTime values from a SQL database in C#

I have high precision dates stored in an SQL server, e.g. 2009-09-15 19:43:43.910 However when I convert that value into a DateTime the miliseconds value of the resulting DateTime value is 0: reader["Timestamp"] = 15/09/2009 19:43:43.000 Having these DateTime values in precision down to milliseconds is very important to me - what i...

How to copy & insert records in table by strored procedure?

I have a table with one field: lngStatusID with value 2 for all the records. Now I need to insert all the records again in the same table but with lngStatusID=1 So for that I think stored procedure will help me somehow. AS per my logic it should be something like: 1) I need to read each record with loop 2) copy all fields in tempora...

Sql Query to Linq To Sql

Hi, I have some difficulties when it comes to multi-table query in Linq to Sql. I have 3 tables: Product Row (with Fk-ProductId) Price (with Fk-RowId) I'd like to retrieve the min(Price) for a product. I was able to get the right Sql query, but now I need to 'translate' this query into Linq To Sql. Can you please help me ? Here the...

Best way to flatten/denormalize SQL lookup tables?

I have a bunch of tables like this: Lookup_HealthCheckupRisks ------------ ID Name 1 Anemia 2 Anorexic 3 Bulemic 4 Depression ... 122 Syphilis PatientRisksOnCheckup ------------------ ID CheckupID RiskID 1 11 2 2 11 3 3 12 1 4 14 1 5 14 3 ... But I need a flattened version, like th...

Exporting SQL Server data to CSV

What’s the quickest way to export SQL Server data to CSV with ALL column fields enclosed in double quotes, including numeric fields? In the Results window of Management Studio, I can right click and choose “Save Results to CSV” but it doesn’t enclose fields in double quotes. I have looked into similar questions but the solutions propo...

Problem with Sql Server query using BETWEEN in where with DATETIME

I have a Stored Procedure that loops through the months in the fiscal year and does a count for the items in each month. I know for a fact there are 176 items, but when I run this it returns a total count of 182. I tried removing one second from @EndDate, but then my total count was 165. So I'm either counting items twice, or not coun...

SQL Server, excecute batch T-SQL script on multiple databases

Our SQL Server 2000 instance hosts several databases which are all similar, one for each of our client. When comes the time to update them all, we use Red Gate SQL Compare to generate a migration script between the development database and a copy of the current state DB of all the clients database. SQL Compare generates a script which i...

Where to see SQL Server start/stop logs?

Hello everyone, I want to know where to see SQL Server start/stop logs for each instances and SQL Server agent/job start/stop logs? I am developing some tools to monitor SQL Server status. I am using SQL Server 2008 Enterprise. thanks in advance, George ...

SQL server database start/stop issue

Hello everyone, I am using SQL Server 2008 Enterprise for development. I find from SQL Server logs, there are items like, 2009-09-20 19:54:33.55 spid53 Starting up database 'DummyOrderDB'. My confusion is, I think we could only start/stop database server instance (the contained database will be started/stopped when the containin...

combine stored procedure in sql and my sql

am writing stored procedure in mysql 5.1 and call from c#.net ..and i want use that procedure in sql server..if its possible..please explain.. ...

Best way to deploy user defined functions to multiple databases in SQL 2005

Hi, I manage a server with around 400+ databases which have the same database schema, i wish to deploy a custom clr/.net user defined function to them all, is there any easy way to do this, or must it be done individually to each database? Best Regards, Wayne ...

SQL 2005 Trigger Not Firing Reliably

I'm currently using Microsoft Sync Framework and everything is working fine except the SQL triggers which don't appear to fire sometimes. Here is the trigger code generated by the framework. It works 90% of the time but occasionally the CreationDate is NULL after an insert. Could there be some date issue that I'm overlooking? set ANS...

SMO some times doesn't display the instances in sql2008 cluster

Hi I have used SMO API.in that i have used SmoApplication.EnumAvailableServers(FALSE) and from that i have filtered local instances i have used this approch insted of true to make this as convinent for remote sqldiscovery also.using that api created a dll and use that dll in c++. Now this is working in all combinations but some times i...

SQL Server 2005 Database 'In Recovery'

This might be a bit of a naive question and probably something I should know by now but here goes.. I restored a 35Gb database on my dev machine yesterday and it was all going fine until this morning when my client app couldn't connect. So I opened SQL Management Studio to find the database 'In Recovery'. I don't know a huge amount a...

How migrate or transfer SQL Server 2008 Compact Edition Database To Express Edition

I have created database in SQL Server 2008 Compact Edition and now I want to migrate that database in SQL Server 2008 Express Edition. How can I achieve this? Please suggest me the necessary steps. As now, this is my project requirement. ...

SQL Server 2008 - Restore Database With RESTART

I am trying to restore a database from a backup file on a SQL Server 2008 instance using the following SQL command: BEGIN RESTORE DATABASE [MyDataBase] FROM DISK=@db_location WITH STATS=5, FILE=1, MOVE @db_OldName TO @db_NewFile, MOVE @db_OldLogName TO @db_NewLogFile, NOREWIND, NOUNLOAD, RESTART, RECOV...

To get total number of columns in a table in sql

hi guys, I need a query in sql to get total columns in a table.Can anybody help? ...

Is it possible combine transaction scope with committing a transaction inside a stored procedure?

We have a test that runs within a transaction scope. We dispose of the transaction scope at the end to avoid changing the database. This works fine in most cases. However, when we use Entity Framework to execute a stored procedure which contains a transaction, which is committed inside the stored procedure. We get the following error: ...

Checking Data in a Large table against a smaller table

Hi, I have 2 tables one with a lot of records(table 1), and a second(table 2) with similar data but with far fewer records. On a regular basis i need to add a marker to records in the larger table where there is a corresponding record in the smaller table. For example this could be an email address. So if email address exists in the s...

How do you comment out a line in a reporting services function?

Nothing I have tried so far has worked... ...