sql-server-2008

SQL Server: how to change login

I have many users in one database. All these users are named using "domain\" as a prefix. I would like to rename these user names by dropping this domain name from the user name. How to do that? In SQL Server Management Studio GUI user name is grayed and cannot be changed? ...

How to use Max function on another column from a select

There is query which is asking for favourite products which is bought by each coustomer. i have to select and in the first select i have selected the count of products that each customer bought. in the other select i want to select the maximum of that boughts for each customer.but when i want to select max(previous select column) it gets...

SQL Server identity column issue

Hello everyone, I am using SQL Server 2008. One int column I used as primary key but not identity column (whose value will be increased by 1 automatically). I want to convert this column to identity column. Any solutions? thanks in advance, George ...

how to find min selling price record in sql server 2008?

ProductPrice table: ProductPriceId,ProductId,CurrencyId,CustomerGroupId,PriceTierId,List,Selling,Bulk 868 1 1 NULL NULL 45.00 42.00 42.00 869 1 1 2 NULL 39.00 36.00 33.00 870 1 3 NULL NULL 48.00 45.00 45.00 871 ...

Read POP3 Email Account with SQL Server 2008

How can I read an accounts emails subject and content, and store these in my SQL Server database? ...

Get T-SQL value using Regular Expressions

I have the following string in database: SET @Value = "[4888378977CA4A5] Test String" Also, the @Value may also have 'RE: ' at the start of the string such as: SET @Value = "RE: [4888378977CA4A5] Test String" How can I access the 4888378977CA4A5 part of the string using regular expressions? Thanks! ...

SQL Server Profiler - View Dynamic Sql

Hi All, I am building and executing some dynamic sql and wanted to use SQL Server profiler to view that execution statement. Do you know what filters /settings I have to use in order to see that? I have looked through them and could be just looking right over the obvious setting. EDIT: The dynamic sql is called within a procedure. T...

How to do a massive insert

I have an application in which I have to insert in a database, with SQL Server 2008, in groups of N tuples and all the tuples have to be inserted to be a success insert, my question is how I insert these tuples and in the case that someone of this fail, I do a rollback to eliminate all the tuples than was inserted correctly. Thanks ...

SQLState=S1000, NativeError=0

I am trying to use the BCP command to execute the following statement, but I keep getting the following error: Starting copy... SQLState = S1000, NativeError = 0 Error = [Microsoft][SQL Server Native Client 10.0]Unexpected EOF encountered in BCP data-file 0 rows copied. Network packet size (bytes): 4096 Clock Time (ms.) Total : 1 ...

How to use EzAPI FlatFile Source in SSIS?

I am using the EzAPI to create a dataflow with FlatFile Source public class EzOleDbToFilePackage : EzSrcDestPackage<EzFlatFileSource, EzFlatFileCM, EzOleDbDestination, EzSqlOleDbCM> Using the example from http://blogs.msdn.com/b/mattm/archive/2008/12/30/ezapi-alternative-package-creation-api.aspx I am trying to use a flat file source....

apply best fitted discount package on items automatically

I have created some discount packages: Package1(Item1,Item2,Item5) Discount-5%. Package2(Item2,Item5,Item8) Discount-8% Package3(Item1,Item2) Discount3%. When a Person buy Items Online(for Ex. he buys Item1,Item2,Item5, Item10), while I show him the total price, I need to apply the best fitted discount on the items automatically. I...

SQL Server 2008 - Cache Dynamic SQL

Hi All, I have Created a Procedure for one of our .Net Devs where they can pass in values that will then build and output a result set. Part of the params they pass in will determine which table gets called. My question is how can I ensure that the dynamic sql statement I am building will get cached for faster execution? None of the c...

How do I use SMO to drop and recreate all views in a Database?

I recently copied a MSSQL2000 DB to a MSSQL2008 DB. Afterwards I ran a script to update all the text/varchar fields in the tables to the same collation as the model db. However, all my copied views still are using the same collation as the previous db. The easiest way I found to fix this would be to have MS SQL Management Studio create t...

Specify max number of databases a user can own.

Is this possible? I would like to have a limit for a user, lets say 5 databases. So when he tries to issue a CREATE query to create a 6th an exception is thrown. ...

How Can I Change Time Zone of DateCreated Column?

The DB resides in SQL Server 2008 ... I have a db that resides in a different country, i want the tables DateCreated and DateUpdated to have Date and Time of e.g. Canada/ON/Toronto time zone instead of the time zone of US where db is located. DateCreated has a default value GetDate() and DateUpdated has the following trigger: CREATE T...

t-sql Aggregate Max

Hi. I have table: CREATE TABLE [dbo].[test] ( [name] nvarchar(max) NULL, [date] datetime NULL ) And records on it: a 2010-09-02 12:00:00 a 2010-09-02 11:00:00 b 2010-09-02 12:00:00 b 2010-09-02 11:00:00 And i want to get all name with the newest date: I may do: select t.[name] from test t group by t.[name] having max(date)...

Dynamic Declare statements SQL Server

Hi, I'm using the varchar(MAX) value for text but as I'm building up the huge SQL it cuts the ending off. Is there any way I can create a Dynamic Declare statement that I can then join together with others when executing the sql? e.g. something like: DECLARE @sSQLLeft + Convertvarchar(4),@index) varchar(MAX) ...

How to send an email message using Microsoft Exchange Server from Sql Server 2005/2008?

I know how to send mail using an SMTP server specified in a mail profiler in the Database Mail of Sql Server. You would do it like so: EXEC msdb.dbo.sp_send_dbmail @profile_name = 'profile', @recipients = @email, @body = @body, @body_format = 'HT...

How to find the name of longest stored procedure ?

Hello, I have a database which contains 100's of stored procedures. I want to find which the longest stored procedure in these. How can i find it? Currently i am using Select text,MAX(len(text)) from syscomments group by text; But i am not able to find the name of stored procedure in it. Thanks in advance :) ...

Creating Data Source Views on a database lacking Primary Keys.

I'm attempting to create data source views on a terribly designed database which lacks primary and foreign keys. I want to be able to use Data Source Views to work with SSRS Report Models. I cannot create them with the wizard because "Add Related Tables" doesn't work and BIDS cannot determine the link. When I re-open the DSV and attemp...