• 0
Sign in to follow this  
JReis

Remover segunda palavra

Question

Boa noite,

Tenho necessidade remover de uma tabela a segunda palavra de uma string. 

Esta minha query tira a primeira palavra ... 

Resultado: Sapatilha ZX 750 

 

Mas preciso de tirar a segunda: 

Exemplo:  Adidas Sapatilha ZX 750 

Resultado: Adidas  ZX 750

 

__________________________________________ Query Inicial ______ 

SELECT  [ItemID]
      ,[LanguageID]
      ,[ShortDescription]
      ,[Description]
      ,dbo.SQLINSTR([Description],' ',1,2)
      ,SUBSTRING([Description], dbo.SQLINSTR([Description],' ',1,1)+1,LEN([Description])-dbo.SQLINSTR([Description],' ',1,1)+1)

      ,[WorkstationID]
      ,[SessionID]
      ,[UserAlt]
      ,[DtAlt]
      ,[HrAlt]
  FROM [A2010Data].[dbo].[ItemNames]

____________________________________________________________________

 

Query do meu update: 

 

Update  [dbo].[ItemExtraFields] SET
      [TextAnswer]=SUBSTRING(b.[Description], dbo.SQLINSTR(b.[Description],' ',1,1)+1,LEN(b.[Description])-dbo.SQLINSTR(b. [Description],' ',1,1)+1)
  FROM [dbo].[ItemExtraFields] a
  INNER JOIN [dbo].[ItemNames] b
  on a.[ItemID]=b.[ItemID]

 

_______________________________

 

 

Agradeço a ajuda. 

 

 

 

 

Edited by JReis

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

em desenvol tente into é feio... mas funciona


--sql2012 ou superior

 Update  [dbo].[ItemExtraFields] SET
      [TextAnswer]=concat(substring([Description],1, charindex(' ', [Description])) , substring([Description],cast(charindex(' ', [Description])+1 as int)+cast(charindex(' ', substring([Description],cast(charindex(' ', [Description])+1 as int),len([Description]))) as int),len([Description])))
  FROM [dbo].[ItemExtraFields] a
  INNER JOIN [dbo].[ItemNames] b
  on a.[ItemID]=b.[ItemID]

--sql2008 ou anterior

Update  [dbo].[ItemExtraFields] SET
      [TextAnswer]=substring([Description],1, charindex(' ', [Description])) + substring([Description],cast(charindex(' ', [Description])+1 as int)+cast(charindex(' ', substring([Description],cast(charindex(' ', [Description])+1 as int),len([Description]))) as int),len([Description]))
  FROM [dbo].[ItemExtraFields] a
  INNER JOIN [dbo].[ItemNames] b
  on a.[ItemID]=b.[ItemID]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this