Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
DECLARE @SQLSTRING NVARCHAR(4000) SET @SQLSTRING = 'SELECT * FROM OPENQUERY( AS400SRV_MSDASQL, ''SELECT yaalphfrom vgiprdhrp.f060116a'')'exec (@SQLSTRING)
Result is (Last and First Name in same field):Alvarez, Saul Hernandez, Frank G. Baloy, Jose Iglesias, Julio I need to split the result into 2 fields respective last name and first name. How can I do this? Thank you.
jimf
Master Smack Fu Yak Hacker
2875 Posts
Posted - 2012-04-11 : 09:42:03
This will work on the data set you provideddeclare @str varchar(50)set @str = 'Hernandez, Frank G. 'select LEFT(@str,CHARINDEX(',',@str)-1),right(@str,CHARINDEX(',',@str))JimEveryday I learn something that somebody else already knew
snufse
Constraint Violating Yak Guru
469 Posts
Posted - 2012-04-11 : 13:16:57
Jim,Using the idea from your post, I had to change the syntax to conform to AS400 / iSeries / db2 and it is working. Thank you.
SET @SQLSTRING = 'SELECT * FROM OPENQUERY( AS400SRV_MSDASQL, ''SELECT substr(yaalph, 1, (locate('''','''', yaalph) - 1)) as LastName, substr(yaalph, (locate('''','''', yaalph) + 1)) as FirstNamefrom vgiprdhrp.f060116awhere yapast = ''''0'''' and yaalph <> '''' '''''')'