| Author |
Topic |
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2009-07-22 : 10:05:47
|
| I am using the familiar structure ofinsert into table a(fields ......)Selectfields .....Fromtable bHowever, some of the values to be inserted are constants, such as today's date. What is the correct syntax for this please (if it can be done) |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-07-22 : 10:13:52
|
| For todays date (with time), use getdate() in your field selection, if you do not want time, use dateadd(dd,0,datediff(dd,0,getdate()))So:insert into table(datefield,restoffields)selectdateadd(dd,0,datediff(dd,0,getdate())) as datedfield,restoffieldsfrom table |
 |
|
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2009-07-22 : 10:25:48
|
| Many thanks for that.So, if I needed to add another constant, such an an integer, for example, I could have something likeinsert into table(datefield,id,restoffields)selectdateadd(dd,0,datediff(dd,0,getdate())) as datedfield,5,restoffieldsfrom table |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2009-07-22 : 10:41:44
|
| yupCharlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2009-07-23 : 03:01:44
|
quote: Originally posted by OldMySQLUser insert into table(datefield,id,restoffields)selectdateadd(dd,0,datediff(dd,0,getdate())) as datedfield,5,True,False,restoffieldsfrom table
If I want to add in True/False values, as above, I get an error 'invalid column names'. How Can I insert true/false values for bit fields please? |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-07-23 : 03:06:51
|
| insert 1 or 0 for the bit fields and while displaying case when field = 1 then 'True' else 'False'or if u want to insert as true change the datatype as varchar field |
 |
|
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2009-07-23 : 03:26:15
|
| Of course! Thanks bklr. |
 |
|
|
|
|
|