Replace a word based upon the file content

I have a file which contains timestamp and date in the second column. If the line contains one of the word then it need to be replace like below. Any help is appreciated.

File:
  a smallint
    b timestamp
    c date
    d varchar
O/P:
    a smallint
    dateformat(b,'YYYY-MM-DD HH:NN:SS.sss')
    dateformat(c.'YYYY-MM-DD')
    d varchar

------ Post updated at 06:21 PM ------

awk '{if ($2=="dateformat') {$1=dataformat($1,'YYYY-MM-DD HH:NN:SS.sss')} else {$2=1}}

------ Post updated at 06:27 PM ------

awk '{if ($2=="dateformat") {$1=dataformat($1,'YYYY-MM-DD HH:NN:SS.sss')} else {$2=1}}' test.out

------ Post updated at 06:34 PM ------

sorry, I have entered dateformat instead of timestamp but still its not working

awk '{if ($2=="timestamp") {$1="dataformat($1,'YYYY-MM-DD')"} else {$2=1}}' test.out

------ Post updated at 07:40 PM ------

If I execute the statement in a separate awk statement then its working fine but If I add in the else condition then I am getting error.

awk '{if ($2=="timestamp") {$3="dataformat(";   }; print $3 $1 ",'\''YYYY-MM-DD HH'\:'NN'\:'SS'\.'sss)" else ($2=="date") {$3="dataformat(";   }; print $3 $1 ",'\''YYYY-MM-DD)" }' test.out 

Error:

awk: {if ($2=="timestamp") {$3="dataformat(";   }; print $3 $1 ",'YYYY-MM-DD HH:NN:SS.sss)" else ($2=="date") {$3="dataformat(";   }; print $3 $1 ",'YYYY-MM-DD)" }
awk:                                                                                        ^ syntax error
awk: {if ($2=="timestamp") {$3="dataformat(";   }; print $3 $1 ",'YYYY-MM-DD HH:NN:SS.sss)" else ($2=="date") {$3="dataformat(";   }; print $3 $1 ",'YYYY-MM-DD)" }
awk:                                                                                                                                  ^ syntax error

------ Post updated at 08:45 PM ------

awk '{if ($2=="timestamp") {$3="dataformat("; }; print $3 $1 ",'\''YYYY-MM-DD HH'\:'NN'\:'SS'\.'sss)" else ($2=="date") {$3="dataformat("; }; print $3 $1 ",'\''YYYY-MM-DD)" }' test.out 

Unfortunately, none of your attempts targets close to what you specify. Did you analyse the very precise error msgs, showing the exact location of the syntax fault? Are you sure about your fields' distribution (you specify two fields but reference $3)?

There are umpteen ways to skin a cat. How far would this get you?

awk -v SQ="'" '
$2 == "timestamp"       {$0 = "dataformat(" SQ "YYYY-MM-DD HH:NN:SS.sss)" SQ}
$2 == "date"            {$0 = "dataformat(" SQ "YYYY-MM-DD)" SQ}
1
' file
a smallint
dataformat('YYYY-MM-DD HH:NN:SS.sss)'
dataformat('YYYY-MM-DD)'
d varchar

EDIT: So close to this (which I saw only now...).