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.
| Author |
Topic |
|
murtzzz
Starting Member
14 Posts |
Posted - 2007-04-26 : 03:33:59
|
| Hi.. Im building a table using data from a script.. and Im trying to put the data in the relevant tables.Ive got 2 major columns called Table Name and Field Name..[dbo].[Tbl_Report_Date]([Rep_Date])Above.. the [dbo].[Tbl_Report_Date] is the table name.. and the rest is the field name.I want to split the two so that the table name stays where it is.. and the field name gets placed into the Field Name column.Please help me on how to do this!Thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-26 : 03:54:55
|
[code]declare @str varchar(100)select @str = '[dbo].[Tbl_Report_Date]([Rep_Date])'select table_name = left(@str, charindex('(', @str) - 1), column_name = right(@str, len(@str) - charindex('(', @str) + 1)[/code] KH |
 |
|
|
murtzzz
Starting Member
14 Posts |
Posted - 2007-04-26 : 04:06:47
|
| That doesnt really make much sense to me... Also.. theres more than one row with the table name.. the above is just an example.. in truth I have about 300 rows.. all that need the Table Name field to be split.. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-26 : 04:19:24
|
replace the @str with your column nameselect table_name = left(yourcol, charindex('(', yourcol) - 1), column_name = right(yourcol, len(yourcol) - charindex('(', yourcol) + 1)from yourtable KH |
 |
|
|
murtzzz
Starting Member
14 Posts |
Posted - 2007-04-26 : 04:48:02
|
| Thanks mate!I tried that.. but it only works for 1 row.. and I get the following message..Invalid length parameter passed to the substring function.What am I doing wrong? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-26 : 04:53:59
|
| Then all your data is not consistent!The suggestion above needs a left paranthesis to be present in all records.Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|