SQL – Table to Table Transfer


Saya mau coba copy isi table dari table InvMail1 ke Mail_Inventory, jadi saya pakai coding seperti ini

di SQLnya. Coding sederhana karena emang belum lama pegang SQL.


 

 

 

 

 

Declare @X int,

@CompCode Varchar(4),

@DeptCode Varchar(4),

@MailBoxName Varchar(50),

@MailAddress Varchar(50),

@Pass Varchar(50),

@Descript Varchar(50)

SET     @X = 9;

WHILE   @X<306

BEGIN

SET @CompCode = (Select Code_Cmpy from InvMail1 where Number=@X)

SET @DeptCode = (Select DeptUser from InvMail1 where Number=@X)

SET @MailBoxName = (Select MailBox from InvMail1 where Number=@X)

SET@MailAddress = (Select Email from InvMail1 where Number=@X)

SET @Pass = (Select [Password] from InvMail1 where Number=@X)

SET @Descript = (Select Company from InvMail1 Where Number=@X)

INSERT INTO MAIL_INVENTORY(

CompCode,

DeptCode,

MailBoxName,

MailAddress,

Pass,

Descript,

CreatedDate,

Flag)

VALUES(

@CompCode,

@DeptCode,

@MailBoxName,

@MailAddress,

@Pass,

@Descript,

GETDATE(),

‘1’)

SET @X=@X+1;

END

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: