Questions tagged [exec]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
48 views

Check the result of a math expression in mysql

Let's say I have a table, which has four columns (a, b, oper and c) and some primary key column. oper means arithmetic operation (+ - * /) here. a b oper c ------------- 2 3 + 5 4 2 / 3 ...
user avatar
  • 123
0 votes
2 answers
289 views

How to combine multiple EXEC statements into a single SELECT?

I run this every month to extract database logs, and I have to change the dates as well. DECLARE @start DATETIME SET @start = CONVERT(DATETIME, '2020-08-01 00:00'); DECLARE @end DATETIME SET @end = ...
user avatar
0 votes
1 answer
89 views

How to use variable in Exec statement [closed]

I'm trying to add my target server to the Multi Server SQ LAgent Job (MSX). We have multiple versions of SQL Agent jobs and I'm trying to automate adding only related targets according to SQL Server ...
user avatar
  • 195
-2 votes
1 answer
77 views

SQL Server: Use Implicit or Explicit Cursor? [closed]

SELECT Table_Name FROM INFORMATION_SCHEMA.TABLES WHILE (1=1) BEGIN EXEC 'drop view ' + Table_Name END or DECLARE my_cursor CURSOR FOR SELECT Table_Name FROM INFORMATION_SCHEMA.TABLES OPEN ...
user avatar
  • 115
1 vote
3 answers
2k views

Must declare the scalar variable question

That is my first post here, need helps: in a stored procedure I had some following code CREATE PROCEDURE [dbo].[SP_getAvg] ( @projectId INT ,@carrierId INT ,@fetchType VARCHAR(20) ) ...
user avatar
  • 21
2 votes
1 answer
2k views

SQL Server: what additional permissions for EXECUTE for implicit result codes?

Tested on: 2014+SP2+CU7, 2016+SP1+CU5, 2016+SP2 Short description: User with EXECUTE permission still gets Cannot find the object 'sp_fakeProcedureName', because it does not exist or you do not ...
user avatar
0 votes
1 answer
1k views

How can I stop script execution if insert value is null and set value if not null?

I have tried to use Case and SET NOEXEC ON but get the following errors: Syntax Error: unexpected 'SET' (set) Syntax Error: missing 'closing parenthesis' INSERT INTO tag (table, repr, tag, ...
user avatar
5 votes
2 answers
2k views

Insert Into table Exec SP with bad performance

I am working on a datawarehouse. One of our staging tables that is refreshed every night has about 10 million rows. We are using a custom built ETL tool that I can't make too many changes to. The tool ...
user avatar
  • 153
11 votes
3 answers
20k views

EXEC vs SP_EXECUTESQL Performance

Recently we used a sql code reviewing tool against our database. It is suggesting to use SP_EXECUTESQL instead of EXEC. I know SP_EXECUTESQL helps us to avoid sql injection. Is there any difference ...
user avatar
0 votes
1 answer
73 views

How can i make SQL exec statements run in order [closed]

SQL server 2012, I have multiple execs calling the same package with different parameters. Normally i'll highlight one at a time and run them individually but I'd like to be able to hit go and run ...
user avatar
1 vote
1 answer
2k views

Insert openquery results into an existing table

I have a stored procedure that queries a linked DB2 server in this fashion: SET @sql='SELECT * FROM openquery(DB2,''SELECT column1, column2 FROM table'')' exec sp_executesql @sql I am trying to ...
user avatar
1 vote
3 answers
2k views

How to extract dynamically data from another database in function with DBName as parameter?

I have one main database (MAIN) and several client DBs (CLIENTDB). I need to start query in MAIN and to get data from CLIENTDB. The client DB can be found also on linked server. My problem is that I ...
user avatar
8 votes
4 answers
18k views

Get @@SERVERNAME from linked server

This seems like a basic question but I can't find any answers out there - I need to be able to get the server name/instance etc. from a linked server. I've tried a couple of things: select <linked ...
user avatar
  • 669