Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL Query help

Author  Topic 

pankaj.pareek@sparrowi.co
Starting Member

26 Posts

Posted - 2007-03-20 : 03:27:04
Help me guys

A table have 5 records only and you have to show 6 records using select query without inserting the record in the database and that record is not present in the database.

Eg.

Table Structure: tab1

id name company salary
1 Pankaj ABC 999
2 Amit XYZ 888
3 Sanjay QWE 9875
4 Raj YUT 456
5 Dev PLKUY 6547

After runnig sql query a additional record is also shown with all the above five records but that record is not present in the table.

Eg. Output

id name company salary
1 Pankaj ABC 999
2 Amit XYZ 888
3 Sanjay QWE 9875
4 Raj YUT 456
5 Dev PLKUY 6547
6 XXX XXXX XXXX

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-20 : 03:33:51
[code]
select id, name, company, salary
from tab1
union all
select 6, 'XXX', 'XXXX', 'XXXX'
[/code]


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-20 : 04:08:27
This smells like homework too.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

pankaj.pareek@sparrowi.co
Starting Member

26 Posts

Posted - 2007-03-21 : 00:10:42
Thank you very much:)
Go to Top of Page

pankaj.pareek@sparrowi.co
Starting Member

26 Posts

Posted - 2007-03-21 : 01:51:32
Another help needed

I need to insert data that is already in the table but with updated id.

Eg.

Table Structure: tab1

id name company salary
1 Pankaj ABC 999
2 Amit XYZ 888
2 Roy XYZ 888
3 Sanjay QWE 9875
4 Raj YUT 456
2 Jack POI 888
5 Dev PLKUY 6547

now what I need is to insert all the records whose id = 2 with new id = 8 in the same table.

Eg. Output

id name company salary
1 Pankaj ABC 999
2 Amit XYZ 888
2 Roy XYZ 888
3 Sanjay QWE 9875
4 Raj YUT 456
2 Jack POI 888
5 Dev PLKUY 6547
8 Amit XYZ 888
8 Roy XYZ 888
8 Jack POI 888

Thanks
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-21 : 01:56:12
If your id column is not IDENTITY column, this should work:

INSERT INTO TAB1([ID], [NAME], COMPANY, SALARY)
SELECT 8, [NAME], COMPANY, SALARY
FROM TAB1
WHERE [ID] = 2


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

pankaj.pareek@sparrowi.co
Starting Member

26 Posts

Posted - 2007-03-21 : 02:05:35
Thank you and I will remember your word UNTRIED.
Go to Top of Page

pankaj.pareek@sparrowi.co
Starting Member

26 Posts

Posted - 2007-03-21 : 02:36:29
Hi,

I need a help to automatically import the data from txt (, seprated) file from specific folder at regular interval into the sqlserver 2000 database table.

This is possiable?

Thanks
Go to Top of Page
   

- Advertisement -