Monday, March 26, 2012

How to INSERT a space?

Hi, how does one normally insert a space in a statement like this:

INSERT INTO table (column0, column1, column2)VALUES (getdate(),'blah',CONVERT(VARCHAR(19),GETDATE(), 120) +'blahblah')
In column2 the output looks like ' 2007-10-08 20:19:08blahblah', but I want it to be like '2007-10-08 20:19:08 blahblah' (two spaces between date and text).

Thanks,
Chris

 

why not this

CONVERT(varchar(19),Getdate(),120)+' '+'blahblah')

|||

INSERT INTO table (column0, column1, column2)VALUES (getdate(),'blah',CONVERT(VARCHAR(19),GETDATE(), 120) +' blahblah')orINSERT INTO table (column0, column1, column2)VALUES (getdate(),'blah',CONVERT(VARCHAR(19),GETDATE(), 120) +' ' +'blahblah')
|||

Hi

Use space function like this

space(0) or space(1) ....

Thank u

Baba

Please remember to click "Mark as Answer" on this post if it helped you.

|||

Also, you can use SqlServer function Space(SpaceNumber). In your case, you can do

VALUES (getdate(),'blah',CONVERT(VARCHAR(19),GETDATE(), 120) + Space(2) + 'blahblah')

|||

Yes, thanks. The Space(*) did it. Could've used the ' ' but that's kind of sloppy, IMO.

No comments:

Post a Comment