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 2008 Forums
 Transact-SQL (2008)
 stored proc help

Author  Topic 

Ratz03
Starting Member

27 Posts

Posted - 2014-11-17 : 16:25:39
am a newbie to sql..i need to writw a stored proc to read table A into new table b with some new cols. see below.

please help...

database A
table 1
name age gender city dob
abc 10 m kl 04-Jun-80


database2
table 2
source year from dob name age city
A 1980 abc 10 kl

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-11-17 : 17:52:38
Table 2 has seven columns but only five values. Can you clarify?



No amount of belief makes something a fact. -James Randi
Go to Top of Page

Ratz03
Starting Member

27 Posts

Posted - 2014-11-18 : 04:00:07
please read (year from dob) as 1 column
Go to Top of Page

AASC
Starting Member

24 Posts

Posted - 2014-11-18 : 04:45:17
@Ratz use this

---- Use database1
use database1
GO

---- create temp table
create table A
(
name varchar(20),
age int,
gender char(1),
city Varchar(20),
dob datetime
)

---- insert dummy data
insert into A
select 'abc', 10 ,'m' ,'kl' ,'04-Jun-80'


--- Query for stored procedure

Create procedure Inserttabledata
AS
insert into database2.dbo.[table 2]
select 'A' [source], datepart(yy,dob ) [year from dob] ,name , [age], [city]
from database1.dbo.A
Go to Top of Page

Ratz03
Starting Member

27 Posts

Posted - 2014-11-18 : 08:04:10
thankyou aasc.
Go to Top of Page
   

- Advertisement -