sql-server-2005

how to send email notificaiton to subscribers (asp.net C#2008 & SQL Server2005)

Hi, I'm new with asp.net and trying to do some code. I have a SQL server 2005 database which contains the members' details and other tables. The members' membership is valid for one year. If they didn't renew their membership the code should send them an Email (which is given in the members' table) before 1 month of the expiry date not...

Best way to move a bunch of SQL Server 2005 tables to another Server?

I've been looking for a way to move a bunch of tables, more than 40, to another server with all the data in them. I've looked around for scripts to generate inserts but so far I'd have to run them once for every table, then copy all the scripts over and then run them on the server. Seems like there is a better way. --Update-- My strate...

SQL FOR XML Help

Prob an easy question, but I am new to forming XML in SQL 2005, but What would be the best FOR XML SQL statement to use to form the XML seen below from a table that looks like this? Column1 Column2 ------------------------ Baseball Football Cricket Polo Swim Beach Desired XML output: <Category Nam...

Is there a way to run a stored procedure at predefined intervals?

Hi I wanted a stored procedure to run at specified intervals everyday. Is there a way to do the same on SQL Server 2005? I know we can create a batch file to run SP and schedule it with windows scheduled tasks but is there a way to do it from SQL Server itself? ...

Get top one record of same FK on date difference.

I need to get top 1 record from same customer inserted within one hour. If record is inserted after one hour then don't need that one. Please see following table. This is just a sample of 1000s of records. I am using SQL Server 2005. ...

Using case statement in update query

Is it possible to use case statement within an update query? I need to do something like this: If person name starts with 'S' then append '1', else append '2'. I tried this in sql server and it didn't work UPDATE PERSON CASE WHEN NAME LIKE 'S%' THEN SET NAME = NAME + '1' ELSE SET NAME = NAME + '2' END ...

SQl Server How to maintain the data.

Hi all, I am working on a product (ASP.NET Web site) developed for educational institutions. There are around 20 educational inst. in my site. For each of them academic year start and end date varies. There are huge number of records in the database for attendance and results. Now I need to show all previous years data (like attendance...

When should I use the SQL Server Unicode 'N' Constant?

I've been looking into the use of the Unicode 'N' constant within my code, for example: select object_id(N'VW_TABLE_UPDATE_DATA', N'V'); insert into SOME_TABLE (Field1, Field2) values (N'A', N'B'); After doing some reading around when to use it, and I'm still not entirely clear as to the circumstances under which it should and should...

What's the equivalent of Postgres' RAISE NOTICE in SQLServer 2005?

I am looking to output a message from a function in MS SQL 2005 when executed from the sql server management studio, similar to Postgres' RAISE NOTICE. ...

Microsoft SQL Server email validation

Using Microsoft SQL Server 2005 and above, what code do I use to validate that an email address is correct? Is there an email data type? Is there an email check constraint? Is there an email rule? Is there an email trigger? Is there an email validation stored procedure? ...

Usage of nested using in C# and SQL Server

This thread is a continuation of http://stackoverflow.com/questions/2220422/is-there-a-reason-to-check-for-null-inside-multiple-using-clausule-in-c I've noticed that resharper lets me define using without opening any opening/closing bracket like in the method below (but then i can't use defined vars later on if the brackets ain't there,...

Need to change my SQL structure for deletion

Ok. I've tried the trigger, but it didn't work. I have Cascades from A to Linker and from B to Linker, Cascade from Users to A, No Action from Users to B. My trigger is on Users and is as follows: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER TRIGGER [trig_delUser] ON [dbo].[aspnet_Users] FOR DELETE AS SET NOCOUNT ON; D...

Error connecting to all of my SQL servers

I suddenly started getting this error when trying to connect to any of my sql servers (25+) from SSMS on Windows XP. When I left work yesterday everything was working fine, came in this morning, and I started getting this. Tried rebooting my pc but that obviously didn't fix it. My co-workers can all connect just fine. Searched for a solu...

Check if Database Exists Before Creating

This seems pretty trivial, but it is now frustrating me. I am using C# with SQL Server 2005 Express. I am using the following code. I want to check if a database exists before creating it. However, the integer returned is -1 and this is how MSDN defines what ExecuteNonQuery() will return as well. Right now, the database does exist but ...

SQL Server 2005: which one is faster? Condition over 2 columns or over 2 rows ?

Table1 ------------ ID IdColumn1 Idcolumn2 Table2 ------------ ID IdColumn IdPair Both of them contains the same data. Table1 have both column populated, Table2 have those columns stored on two rows. So, if Table1 contains n rows, Table2 will have 2 * n rows Wich query is faster ? select * from Table1 where IdColumn1 = x or IdCol...

Aggregate data from view as UDF to use in select statement

I have an existing view that returns data in the following format. option_name product_id XSMALL (2-6) 17854 SMALL (6-10) 17854 MEDIUM (10-14) 17854 LARGE 18232 How do I return this data in a comma separated field formatted like this, based on sending a product_id to the function? ...

How to Encrypt Stored Procedure

Hi All, We can precompile our (ASP.NET) websites and can publish only the IL code, so that the source code is not available to the customer. But how do we do it for stored procedures written in SQL Server. I mean, when we give the customer the DB, he could see all my stored procedures and can modify the same... How could I protect it....

select records which are repeated twice!

I have a table in SQL Server with these records : ID Date Time -- --------- ---- 1 09/05/02 6:00 2 09/05/02 8:00 3 09/05/03 6:00 4 09/05/04 8:00 5 09/05/04 6:00 I would like to select those ID who have records in a day which are repeated twice or multiple of two. How wo...

Stored proc Timeout in Reporting Services : explanations and workaround

Symptoms A stored procedure that excecutes in a timely fashion ( from 10 to 30 seconds ) in SSMS takes up to 15min or hangs on Reporting Services or Visual Studio 2005. Tried in my case I made sure to use the same parameters and the same security context on both. cutting and pasting the stored procedure body doesn't work, due to som...

Export tables in SQL Server 2005

In SQL Server 2000 you had DTS where you had the option to choose to export table structure along with data and also to choose specific tables only. Is there a similar option in SQé Server 2005 version. I would like to export just 5 tables along structure and data from an existing database to another database. The data is required as i...