sql-server

How to repeat the row values

How to repeat the row values up to end date For Example Table1 Date Name Dept ----------------------- 12-02-2009 Raja IT 13-02-2009 Ravi CSE 14-02-2009 Ramu ECE From the above table value i want to repeat the value between the two dates from 12-02-2009 to 12-03-2009. Expected Output Date Name Dept ...

Using System Views

This is a general question that keeps coming to my mind. Is there any major disadvantage in using the SQL Server 2000 system tables in SQL Server 2008? It is a good practice to use system views, but in simple words, Why? ...

SQL Server: Filter output of sp_who2

Under SQL Server, is there an easy way to filter the output of sp_who2? Say I wanted to just show rows for a certain database, for example. ...

Is .sql file different for MySQL and SQL?

I have a .sql file and I want to load it into MySQL database. I don't know from which database (MySQL or MS-SQL) it was created. Now, I am trying to import that file into MySQL database. It is showing errors while importing and executing that file. Q1. So, my question is whether the .sql file generated from MySQL and MS-SQL are diff...

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...

ADO.NET and SQL Server stored procedures - SELECT after INSERT, UPDATE, DELETE

In a large project relying on SQL Server stored procedures and classic ADO.NET (DataSets, DataAdapters) after INSERT, DELETE and UPDATE procedures there is a SELECT following. In code, all the methods return void, is this SELECT of any relevance - what effect does in have? What is the performance impact of the SELECT? ...

How can my application use both an MS Access database and a SQL Server database at the same time?

What strategies and techniques have you used to produce a data driven application that needs to access multiple diverse data sources? Specifically, Microsoft Access and SQL Server. Ideally, I'd like to make an abstraction layer that hides the physical data source from the application. Something like the ADO.NET Entity Framework would ...

How to Join tables to get the result

I am having data like below Table1 data: Attr1 Attr2 36 L 37 L 38 L 39 L 40 L 41 L 42 L 43 L 44 L 46 L 48 L 50 L 52 L 54 L 56 L 58 L 60 L 62 L 36 P 37 P 38 P 39 P 40 P 41 P 42 P 43 P 44 P 46 P 48 P 50 P 52 P 54 P 56 P 58 P 60 P 62 P 36 PL 37 PL 38 PL 39 PL 40 PL 41 PL 42 PL 43 PL 44 PL 46 PL 48 PL 50 PL 52 PL 54 PL 56 PL 58 PL 60 PL...

T-SQL: How to calculate a gand total of values

I'm trying to perform calculations in T-SQL, but am having some problems with it. Here is what I'm trying to do: DECLARE @CNT money SELECT @CNT = 0 Select Amount, case when Service like 'pay_in' then SET @CNT = @CNT + Amount when Service like 'pay_out' then SET @CNT= @CNT - Amount end from Pa...

TSQL update trigger: joining inserted and deleted

I have an on update trigger in SQL Server 2008. I only need to perform the trigger action if certain columns have been modified. Thus I'd like to check what has changed. T-SQL offers an "if update( columnName )" construct. However, if many rows have been updated and only a single one of them has the particular column value changed "if...

SQL Server Full-Text Search - No hit even though the word is present

Hi, I'm having problems with Full-Text Search on SQL Server 2005. In my setup, I am indexing a single column, let's call it Content. The indexing is done in the neutral culture since the column might contain text in different languages. The fulltext index is created as follows: CREATE FULLTEXT INDEX ON [dbo].[Table1]([Content]) KEY IN...

SQL Server trigger - connection info

is it possible to get MSSQL connection info?not onli SUSER_ID(), SUSER_NAME(), ORIGINAL_LOGIN(), BUT other like: IP Connection string ect.. ...

Combining two datetime fields into two separate columns in T-SQL

Hello, I'm trying to create a view that displays events with start and end time. This view should be gathered from an existing table that only has an event time field and event type field. So the current EventTable looks like this: EventTime | BooleanField ------------------------------ 1/1/2010 6:00AM 1 1/2/2010 6:00AM ...

SQL Server Trigger loop

Hi, I would like to know if there is anyway I can add a trigger on two tables that will replicate the data to the other. For example: I have a two users tables, users_V1 and users_V2, When a user is updated with one of the V1 app, it activate a trigger updating it in users_V2 as well. If I want to add the same trigger on the V2 table...

SELECTING Only Part of nvarchar SQL Server 2005

Hello, I'm transferring data from one database to another (upgrading a system) and have a quick question. In the source database (the one currently in use), I have a column that stores urls using absolute paths. In my new database, I am using relative paths. How can I trim out the absolute portion of the paths on the transfer (I'm using...

SqlBulkCopy WriteToServer example. What am I doing wrong?

This might be long, but I want to explain my example I got this Code: #region [parent table] DataTable dtParent = new DataTable(); DataColumn dc; dc = new DataColumn(); dc.DataType = System.Type.GetType("System.Int32"); dc.ColumnName = "Id"; dc.Unique = true; dc.AutoIncre...

SQL what is faster left 2 or convert(varchar(2),'Chgffgjjx')

If I want to return the first two characters of a string which is the best / fastest method? Also if I have a date and want to group by day I will use convert(varchar(10),getdate()) as our db format is in yyyy/MM/dd, which would give '2010/02/10' if I wanted to group by month I would use varchar(7) instead to give '2010/02' Is there a...

Backup SQL 2008 DB to restore on SQL 2000 .NET

We have cutomers interested in sending their Sql 2008 data to other customers with SQL 2000. Now obviously this does not currently work, so I'm attempting to create a "generic" backup process that allows us to backup and restore our data on Server 2000 and up (since SQL2000 is the least common denominator of all or customers). Right now ...

How to aggregate data into view with the same ID

I have an existing view that returns data in the following format based on aggregating option names that have the same product_id. The view name is "vProdOptions" option_name product_id XSMALL (2-6) 17854 SMALL (6-10) 17854 MEDIUM (10-14) 17854 LARGE 18232 How do I return this data i...

Very Simple Stored Procedure Will Time Out.

I have a problem with this one stored procedure that works 99% of the time throughout our application, but will time out when called from a particular part of the application. The table only has 3 columns and contains about 300 records. The stored proc will only bring back one record and looks like this "Select * from Table Where Col...