sql-server

SQL Server, choosing from two TABLEs using IF statement inside WHERE statement depending on the parameter

Hello All, How can I do the following in SQL Server DECLARE @Local nvarchar(20) SET @Local = 'True' SELECT * FROM My_Table WHERE my_ID IN (IF @Local = 'True' SELECT AllIDs FROM ATable ELSE SELECT TeamIDs FROM TeamTable ) ...

How to get a dataset value

New to VB.Net, How to insert or select the dataset value. cmd = New SqlCommand("Select * from table1", con) ada = New SqlDataAdapter(cmd) ds = New DataSet ada.Fill(ds) cmd = New SqlCommand("Select * from '" & ds.Tables(0) & "' ", con) mydatatable1.Load(dr3) It was showing the error in '" & ds.Tables(0) & "',...

Rounding money to a decimal in SQL Server

I am trying to round to 3 decimal places from two variables of type money in SQL Server 2008. DECLARE @Val1 money = 554.5344 DECLARE @Val2 money = 84020.37 DECLARE @Result decimal(6,5) = @Val1/@Val2 *100 SELECT @Result The result above is 0.65. With a calculator it is 0.65999995001212, I need the result to be 0.659. ...

How can we dis-connect all the active users on sql-server 2005 express using sql

How can we dis-connect all the active users on sql-server 2005 express using sql ...

How do I get the nth row in a SQL Server table?

how would you get the 5 value from a row of data. ...

IF EXISTS before INSERT, UPDATE, DELETE for optimization

There is quite often situation when you need to execute INSERT, UPDATE or DELETE statement based on some condition. And my question is whether the affect on the performance of the query add IF EXISTS before the command. Example IF EXISTS(SELECT 1 FROM Contacs WHERE [Type] = 1) UPDATE Contacs SET [Deleted] = 1 WHERE [Type] = 1 Wha...

Local Data Cache Sync Framework table loses ability to use Default values

Hi, I have a clinet sdf file (sql compact) that is created by the LocalDataCache.sync in Visual Studio 2008. The server is SQL Server 2008. On the server if I do the following: CREATE TABLE test ( [firstfield] float NOT NULL DEFAULT 1, [secondfield] float NOT NULL DEFAULT 2) GO INSER...

SQL Connection works on main thread but fails on BackgroundWorker thread!!

Hi everyone, I have a strange problem. The SQL server data access works fine in the main thread but fails if i call the same from a background worker thread. Please help. I dint find anything on the net except i that suspect HostProtectionAttribute of BackgroundWorker. When i try to open the connection on the background thread i get the...

test ssis package configurations - connection managers

What would be the best method to use for testing that connection managers are correctly pulling their connection strings from the package configurations on multiple packages (In VS 2008). In the past I have created a data flow which ran the query select @@servername and outputed to a text file. While this works, it seems a bit redundan...

How to convert a byte[] into datetime in C#?

I have a field of type TimeStamp in database, which is converted in byte[] in c# code, and i need to convert it to DateTime value. So i want to convert from an array of bytes into DateTime. Already used this code: byte[] byteValue = someValue; long longVar = BitConverter.ToInt64(byteValue); DateTime dateTimeVar = DateTime.FromBinary(lo...

Prevent query rewriting in SQL Server

I have a column TypeCode varchar(20) that has values like '1', '2', '3', 'FOO', 'BAR'. I need to find the maximum integer which is less than the value of parameter. Something like this: select max(TypeCode) TypeCode from table1 a left join table2 b on b.table1id = a.id and b.TypeCode not in ('FOO', 'BAR') where b.Typ...

Get length of Columns using SQL Server Management Objects (SMO)

I'm writing T4 templates to generate CRUD stored procs etc I am looping through the columns of a table using SMO: For Each column As Column In table.Columns WriteLine("@" & column.Name & " " & column.DataType.Name & ", ") Next My question is simply how do I find the Length of a varchar column? There doesn't appear to be any Lengt...

SQL Server Service Broker -- Communicating Between Non-Domain Servers Over a VPN

Are there any good options for connecting two SQL Server 2008 instances via Service Broker if neither of those servers are in a domain, but we have full control over the logins and credentials? We're thinking of using this technology for enterprise-level data consolidation, but our servers run at client sites and are not configured as m...

Detect last login date/time in SQL Server 2000

Is there a way of determining when a given user last logged into SQL Server? We are about to carry out an audit of our database server and would like to delete users that are redundant. Incidentally I'm interested in users at the server-level (i.e. Logins), not users of individual databases. Thanks in advance. ...

How do I set up security on Sql Server to allow access by a WCF service?

I have a WCF service hosted within IIS that logs information in a sql server 2008 db. I have successfully tested this within my local IIS and SS2008 db (using an application pool running under my windows id). Now I have moved the database and wcf service to the production server and wondering how to set the security up on the database t...

How to create database diagrams in SQL Server 2008 express?

I am using SQL Server 2008 express version but don't know how to generate database diagrams. When I click the Database Diagrams, it give me an error diagram tell me "Database diagram support objects cannot be installed because this database does no thave a valide owner. ...." I follow its instruction and cannot find anything wrong. Anybo...

SQL - How to ALTER COLUMN on a computed column

I'm working with SQL Server 2008. Is it possible to alter a computed column without actually dropping the column and then adding it again (which I can get to work)? For example, I have this table: CREATE TABLE [dbo].[Prices]( [Price] [numeric](8,3) NOT NULL, [AdjPrice] AS [Price] / [AdjFactor], [AdjFactor] [numeric](8,3) NOT NULL) La...

SQL server: How to check database has catalog or not

I am trying to find out whether a database has a catalog or not. I couldn’t find any system stored procedure to perform this task. I need to find the catalog first then perform Full text search. If a catalog is not found, full text search is ignored. ...

How to take the backup of live sql server 2005 express DB

How to take the backup of live sql server 2005 express DB ? At any given time some transaction are in progress. ...

What is the best way to encrypt SSNs in SQL Server 2008?

I am developing a new web application using .NET 3.5 and SQL Server 2008 that will need to store some Social Security Numbers. I've been doing some initial reading on database encryption and it's a little bit confusing. I would be nice to encrypt the SSNs using an asymmetric key, since that way the public facing application wouldn't be ...