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
 General SQL Server Forums
 New to SQL Server Programming
 inserting the data

Author  Topic 

velliraj
Yak Posting Veteran

59 Posts

Posted - 2010-07-01 : 09:45:53
Hi

As per the below scenario i have to insert the data into a table

select empid,empname,dob,phone from employee
where
isnumeric(empid) = 0
or
empname is null
or
empname = ''
or
dob is null
or
isnumeric(phone) = 0

empid empname dob Phone
3 1900-01-01 00:00:00.000 2
4 NULL 1900-01-01 00:00:00.000 NULL

values having the empty spaces and null should be inserted into a table in the below manner

empid values columnname
3 empname
4 Null empname
4 Null Phone

please help how to insert




webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-01 : 10:00:59
To create a new table on the fly named bad_data for example:
select empid,empname,dob,phone
into bad_data
from employee
where ...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-07-01 : 10:05:24
quote:
Originally posted by webfred



into bad_data



No, you're never too old to Yak'n'Roll if you're too young to die.



Why that name?


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-07-01 : 10:07:03
ummmm why do you need another table?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-01 : 10:11:42
quote:
Originally posted by Idera

quote:
Originally posted by webfred



into bad_data



No, you're never too old to Yak'n'Roll if you're too young to die.



Why that name?


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH


Because the OP obviously is selecting bad data.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-07-01 : 10:14:16
quote:
Originally posted by velliraj

Hi

As per the below scenario i have to insert the data into a table

select empid,empname,dob,phone from employee
where
isnumeric(empid) = 0
or
empname is null
or
empname = ''
or
dob is null
or
isnumeric(phone) = 0

empid empname dob Phone
3 1900-01-01 00:00:00.000 2
4 NULL 1900-01-01 00:00:00.000 NULL

values having the empty spaces and null should be inserted into a table in the below manner

empid values columnname
3 empname
4 Null empname
4 Null Phone

please help how to insert







There's definitely a better way, but may be this?
;with cte_bad_data  (empid,empname,dob,phone)
AS
(
select empid,empname,dob,phone from employee
where
isnumeric(empid) = 0 or isnumeric(phone) = 0 or coalesce(empname,'') = '' or dob is null
)

select empid, empname as [value], 'empname' as [columnname]
from cte_bad_data
union all
select empid,dob,'dob'
from cte_bad_data
union all
select empid,phone,'phone'
from cte_bad_data
Go to Top of Page
   

- Advertisement -