Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
<pre lang="c#">USE [test]
GO
/****** Object:  StoredProcedure [dbo].[spSendSmsSQL]    Script Date: 02-07-2019 10:04:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[spSendSmsSQL] 
    --@Mobile varchar(20), 
    --@smstext as varchar(200)
AS
BEGIN
    declare @Mobile as varchar(200) 
    declare @smstext as varchar(200)
    DECLARE @iReq int, @hr int 
    DECLARE @sUrl AS varchar(500) 
    DECLARE @errorSource VARCHAR(8000)
    DECLARE @errorDescription VARCHAR(8000) 

    EXEC @hr = sp_OACreate 'Microsoft.XMLHTTP', @iReq OUT        

    print @hr        

    if @hr <> 0     
        RAISERROR('sp_OACreate Microsoft.XMLHTTP FAILED!', 16, 1) 

	set @Mobile=(select MobileNo from tbl_MobileNo)
	set @smstext='This is line 1.' + CHAR(10) + 'This is line 2.'
	
SET @sUrl='http://xxxxxxx/smpp/sendsms?username=xxx&password=xxx&to=#MobNo#&from=Al Ahli D C&text=#Msg#'
    SET @sUrl = REPLACE(@sUrl,'#MobNo#',@Mobile) 
    SET @sUrl = REPLACE(@sUrl,'#Msg#',@smstext) 

    -- sms code start 
    EXEC @hr = sp_OAMethod @iReq, 'Open', NULL, 'GET', @sUrl, true 

    IF @hr <> 0 
        RAISERROR('sp_OAMethod Open FAILED!', 16, 1) 

    EXEC @hr = sp_OAMethod @iReq, 'send' 

    SELECT @iReq

    IF @hr <> 0 
    BEGIN 
        EXEC sp_OAGetErrorInfo @iReq, @errorSource OUTPUT, @errorDescription OUTPUT

        SELECT 
            [Error Source] = @errorSource,
            [Description] = @errorDescription

        RAISERROR('sp_OAMethod Send FAILED!', 16, 1) 
    END 
    ELSE 
        EXEC @hr = sp_OAGetProperty @iReq 
END


What I have tried:

I am trying to send SMS from MSSQL server using SMS Gateway. But SMS is going in paragraph Like "This is line 1.' + CHAR(10) + 'This is line 2. " i want break line or new line for next word how i can achieve from MSSQL Server.
i want SMS like that
This is line 1.
This is line 2.
Posted
Updated 1-Jul-19 23:46pm

1 solution

I'd not recommend to format SMS on SQL Server site for set of reasons. Use UI instead.

But, if you would like to know why CHAR(10) does not work with SELECT statement, please read this:
c# - Line break in T-sql (Char(13)) is not working - Stack Overflow[^]
How to insert a line break in a SQL Server VARCHAR/NVARCHAR string - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900