Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8832487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:32:31+00:00 2026-06-14T08:32:31+00:00

I have a problem when trying to send a variable from the @ query,

  • 0

I have a problem when trying to send a variable from the @ query, this variable is sent by a trigger, the variable goes well with the procedure, the print and show what I send, the problem occurs when I try to take that variable to select not I take the variable, just take the value of what I write.

The mail is working fine without problems if you only write text. I also take data from a normal query, but if I include a variable fails.

I chose to put the variable in the select so ‘+ @ q +’ and displays the error

Msg 102, Level 15, State 1, Procedure Facturacion_Tope, Line 29
Incorrect syntax near ‘+’.

and remove the single quote symbol + and is not a fixed value and variable

USE [sistemas]
GO
/****** Object:  StoredProcedure [dbo].[Facturacion_Tope]    Script Date: 11/15/2012 07:32:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[Facturacion_Tope]
    @ENVIO INT 
AS
print @ENVIO
BEGIN

    SET NOCOUNT ON;
    Declare @q INT
    --here shows the value of consultation 
    print @ENVIO

    set @q = (select OID from sistemas..DATFACTUR_DINAMICA WHERE OID = @ENVIO)

    --here shows the value of consultation
    print @q

    EXEC msdb.dbo.sp_send_dbmail
      @profile_name = 'correo_sistemas',
      @recipients = 'diegom_montes_contratista@clinica.com.co',
      -- @execute_query_database = 'sistemas',
      @query = 'select * from sistemas..DATFACTUR_DINAMICA WHERE OID = "@q"',                       
      @query_attachment_filename = 'Consulta.txt',      
      -- @body = 'Caida en: '@query+'', 
      @body_format = 'HTML',
      @subject = 'Numero de factura';
END

This is the output of the stored procedure.

209 –prints well
209 – prints well
HAY VA –prints well
209 –prints well
Msg 22050, Level 16, State 1, Line 0
Error formatting query, probably invalid parameters
Doomed Error 14661 on line 504, Query execution failed: Msg 137, Level 15, State 2, Server CDPALWIN01\CDPALSQL02, Line 1
Must declare the scalar variable “@q”.
Msg 3903, Level 16, State 1, Procedure DEVDATFAC, Line 180
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
The statement has been terminated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:32:33+00:00Added an answer on June 14, 2026 at 8:32 am

    Set the @query parameter beforehand, and then use that as a simple variable rather than concatenating strings in the procedure parameter assignment.

     DECLARE @thequery nvarchar(max) = 'select * from sistemas..DATFACTUR_DINAMICA
                                        WHERE OID = ' + cast(@q as nvarchar(max));
     EXEC msdb.dbo.sp_send_dbmail
     @profile_name = 'correo_sistemas',
        @recipients = 'diegom_montes_contratista@clinica.com.co',
       -- @execute_query_database = 'sistemas',
        @query = @thequery,                     
        @query_attachment_filename = 'Consulta.txt',      
      -- @body = 'Caida en: '@query+'', 
       @body_format = 'HTML',
        @subject = 'Numero de factura';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when trying to send a POST request. The sending method
I have a bit of a strange problem. I am trying to send in-app
I have a problem trying to hide .php extension from the url I have
I have a problem when trying to execute this update statement (below) using C#
Ok now i have another problem i want to send one or more variable
I have a problem trying to turn my python code into an executable using
I have a problem trying to register my own Event/Listener to the event dispatcher.
I have a problem trying to design some generic storage.. Basically I have the
I have a problem trying to edit. I work with Areas for better management
I implemented the table sorter yesterday and i have a problem trying to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.