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
 General SQL Server Forums
 New to SQL Server Programming
 removing 0 and copying fields to other tables

Author  Topic 

eem_2055
Yak Posting Veteran

69 Posts

Posted - 2008-05-19 : 06:06:46
Hi guys,

please help.

I use to copy one column from one database to another database. What query should I use?

moreover,

How can I convert this

code
000001

the result would be
code
1

thanks!





Lumbago
Norsk Yak Master

3271 Posts

Posted - 2008-05-19 : 06:20:59
1: INSERT INTO db1.dbo.tablename (Column1) SELECT Column1 FROM db2.dbo.tablename
2: SELECT CAST(code AS int)


--
Lumbago
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-19 : 06:22:54
[code]DECLARE @Sample TABLE (Info VARCHAR(20))

INSERT @Sample
SELECT '000001' UNION ALL
SELECT '000020'

SELECT Info,
REPLACE(LTRIM(REPLACE(Info, '0', ' ')), ' ', '0') AS Peso1,
SUBSTRING(Info, PATINDEX('%[^0]%', Info), 8000) AS Peso2
FROM @Sample[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-19 : 07:03:45
SELECT Info,info*1
FROM @Sample


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

eem_2055
Yak Posting Veteran

69 Posts

Posted - 2008-05-19 : 07:11:41
how about?

code
000001

the result would be
code
01
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-19 : 07:18:52
[code]DECLARE @Sample TABLE (Info VARCHAR(20))

INSERT @Sample
SELECT '000001' UNION ALL
SELECT '000020'

SELECT Info,
REPLACE(LTRIM(REPLACE(Info, '0', ' ')), ' ', '0') AS Peso1,
SUBSTRING(Info, PATINDEX('%[^0]%', Info) - 1, 8000) AS Peso2
FROM @Sample[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -