-1

Example, I get data from eclipse and insert into 'abc' table.

so, now how I can get the data from the 'abc' table and concat the digit?

Example: I enter 123456 then in SQL need to concat into format 123-456

I created procedure and alter procedure. I can insert but I can't select and concat and insert. I want it to be in a column.

this is create procedure

USE abc
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE TEST

    @cd VARCHAR(14)

AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO abc (a) VALUES (@cd)

FROM abc

END
GO

here is the alter procedure

USE [abc]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[abc]

    @cd VARCHAR(14)

AS
BEGIN

    SET NOCOUNT ON;

    INSERT INTO abc(a) VALUES (@cd)
     Select CONCAT(SUBSTRING(abc, 1,3), '-',
    SUBSTRING(abc,4,3)
from abc

END
GO
1

I'm a little confused about what you're really trying to do.

Your INSERT procedure has a rogue FROM abc in it which would error. Your INSERT statement should simply be:

INSERT INTO abc (a) VALUES (@cd);

Now, if you're wanting to change the data that's already the table, use UPDATE.

 UPDATE abc SET a = CONCAT(SUBSTRING(a, 1,3), '-', SUBSTRING(a,4,3));

Or if you're wanting to insert a new row that's concatenated, use the variable:

INSERT INTO abc (a) VALUES (CONCAT(SUBSTRING(@cd, 1,3), '-', SUBSTRING(@cd,4,3)));

or

INSERT INTO abc (a)
CONCAT(SUBSTRING(a, 1,3), '-', SUBSTRING(a,4,3));
| improve this answer | |
  • Hi Sir,thank you very much for guiding me now i can concat 123456 into 123-456. Thank you ! – lovely Mar 17 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.