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.
| 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 employeewhereisnumeric(empid) = 0orempname is nullorempname = ''or dob is nullorisnumeric(phone) = 0 empid empname dob Phone3 1900-01-01 00:00:00.000 24 NULL 1900-01-01 00:00:00.000 NULLvalues having the empty spaces and null should be inserted into a table in the below manner empid values columnname3 empname4 Null empname4 Null Phoneplease 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_datafrom employeewhere ... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
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 |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
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. |
 |
|
|
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 employeewhereisnumeric(empid) = 0orempname is nullorempname = ''or dob is nullorisnumeric(phone) = 0 empid empname dob Phone3 1900-01-01 00:00:00.000 24 NULL 1900-01-01 00:00:00.000 NULLvalues having the empty spaces and null should be inserted into a table in the below manner empid values columnname3 empname4 Null empname4 Null Phoneplease 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 employeewhereisnumeric(empid) = 0 or isnumeric(phone) = 0 or coalesce(empname,'') = '' or dob is null) select empid, empname as [value], 'empname' as [columnname]from cte_bad_dataunion allselect empid,dob,'dob'from cte_bad_dataunion allselect empid,phone,'phone'from cte_bad_data |
 |
|
|
|
|
|
|
|