sql

Self join to a table

I have a table like Employee ================== name salary ================== a 10000 b 20000 c 5000 d 40000 i want to get all the employee whose salary is greater than A's salary. I don't want to use any nested or sub query. It has been asked in an interview and hint was to use self join. I really c...

How to make an SQL query to get some specific range of rows from Table

How to make an SQL query if there are 30 records in table and I want to pick rows from 12 to 20 where 12 and 20 are row numbers not Ids. Ids Code 5 ABC 6 SDF 8 WSA 10 FSD 15 IOP . . . . 80 AWS ...

How to write query for remove and alter unique columns

My scenario..Im using SqlCompactServer Edition .I'm creating table Create Table SSr( name nvarchar(400),id int unique).I need to alter table and make name as UNIQUE Column and remove unique from existing column. How to Achieve this. ...

sql strictly equals, is there something ?

Possible Duplicate: SQL server ignore case in a where expression basically I need to check something like this select * from users where name = @name, pass = @pass the problem is that 'pass' = 'pAsS' is there something more strict for string comparison in sql (ms sql-server) ...

Have any idea about to add column by stored procedure?

I want to add column to table by stored procedure and the name of column should be parameter.'s value. ...

Random select is not always returning a single row.

The intention of following (simplified) code fragment is to return one random row. Unfortunatly, when we run this fragment in the query analyzer, it returns between zero and three results. As our input table consists of exactly 5 rows with unique ID's and as we perform a select on this table where ID equals a random number, we are st...

Group by SQL with count

Lets say we have got rows like that: MyTable ID Name Product ------------------ 1 Adam x 2 Adam y 3 Adam z 4 Peter a 5 Peter b Using query like: Select Name, Count(Product) from MyTable group by Name results will be: Adam 3 Peter 2 But I would like results like: 1 Adam x 3 2 Adam y 3 3 Adam z 3 4 Peter a 2 5 Peter b ...

Is The Transaction Log Truncated When Doing a Backup In Full Recovery Mode?

Is the database transaction log automatically truncated after we create a backup and the DB is in full recovery mode? Or do we need to make 2 different backups, let's say 1 in full recovery mode and a different one for the log file. ...

How to retrieve large data from oracle database using vbscript

Hi guys, I'm now working on vbscript to do some test. Actuelly, I want to retrieve a large amount of data from an oracle database, so I write the code like this: sql = "Select * from CORE_DB where MC = '" & mstr & "' " Set myrs = db_execute_query(curConnection, sql) Then I count the rows in myrs,there are 248 rows. So then I do a For...

Extract whole SQL Server database to CSV file

It is possible to extract all tables and rows of each table with one query or software in microsoft sql server? thanks ...

Why doesn't the OFFSETS function respect docid condition?

Why does SELECT OFFSETS(Data) FROM Data WHERE docid = 1 AND Data MATCH 'term' take same time as SELECT OFFSETS(Data) FROM Data WHERE Data MATCH 'term' And how can I make it work fast, i.e. just for one record? Thanks! ...

How do I iterate through hierarchical data in a Sql Server 2005 stored proc?

Hi, I have a SqlServer2005 table "Group" similar to the following: Id (PK, int) Name (varchar(50)) ParentId (int) where ParentId refers to another Id in the Group table. This is used to model hierarchical groups such as: Group 1 (id = 1, parentid = null) +--Group 2 (id = 2, parentid = 1) +--Group 3 (id = 3, parentid = 1) ...

MS Sql Full-text search vs. LIKE expression

Hi. I'm currently looking for a way to search a big database (500MB - 10GB or more on 10 tables) with a lot of different fields(nvarchars and bigints). Many of the fields, that should be searched are not in the same table. An example: A search for '5124 Peter' should return all items, that ... have an ID with 5124 in it, have 'Peter'...

Best way to perform a SELECT statement and insert into the same table?

Does anybody have any suggestions on how to improve the following statements: insert into ProductInfo with (rowlock) (orderid, productname) select 66673, FileInfoId from ProductInfo with (nolock) where ProductId = 66671 and IsEligableForCopy = 1 and ProductFileInfoId >= 2768395941 and ...

Why is [date] + ([time] - [offset]) non-deterministic in SQL Server 2008?

I'm trying to do the following for my IIS logs table: ALTER TABLE [W3CLog] ADD [LogTime] AS [date] + ([time] - '1900-01-01') PERSISTED However, SQL Server 2008 tells me: Computed column 'LogTime' in table 'W3CLog' cannot be persisted because the column is non-deterministic. The table has this definition: CREATE TABLE [dbo].[W3CLog]...

Data Access from single table in sql server 2005 is too slow

Following is the script of table. Accessing data from this table is too slow. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Emails]( [id] [int] IDENTITY(1,1) NOT NULL, [datecreated] [datetime] NULL CONSTRAINT [DF_Emails_datecreated] DEFAULT (getdate()), [UID] [nvarchar](250) COLLATE Latin1_Ge...

SQL: 2 Counts using joins?

I have these 2 tables: Table: Unit UnitID | Title 1 Unit 1 2 Unit 2 3 Unit 3 Table: Piece PieceID | UnitID | Category 1 1 A 2 1 A 3 1 B 4 2 A 5 3 B What I need to do is show a count of the total units containing Piece rows with Categ...

SSIS FTP Task - get FTP result back

I am selecting data from a table using FOR XML and outputting it to a file, then need to only FTP the file if the destination directory is empty. using SSIS, how do i get the result back to base my next step on. If the destination file already exists then it should NOT be overwritten and the items in the transfer should not be marked a...

Restore DB - Error RESTORE HEADERONLY is terminating abnormally.

I have taken backup of SQL Server 2008 DB on server, and download them to local environment. I am trying to restore that database and it is keep on giving me following error. An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) ------------------------------ ADD...

Command dialect is not supported by this provider.

Hi Have and old ASP website have just updated SQL DB to 2005 Can now log into database however certain commands within the pages are returning this error.. Error Details: Category=Microsoft SQL Native Client Number=-2147217898) Description=Command dialect is not supported by this provider. Filename=/home/_private/Includes/SQLServer.as...