Getting data from SQL server

MartinL

Well-known Member
Joined
Oct 16, 2008
Messages
1,141
Office Version
  1. 365
Platform
  1. Windows
Hi all
I am attempting to get data from a SQL Server database Stored Procedure.
I need to pass some variables to SQL, but cannot work out how to do this - well I can send a fixed set of variables but these tend to change 3 or 4 times a year.

This is my Source code:
SQL:
= Sql.Database("SERVER", "DBNaame", [Query="EXEC stored_procedure @SCE = '117,118,148,151,152,159,163', @REG = '', @SBU = '20,64,69,63,67,68,93,65', @BUN = 0 ,@PRC = 0 ,@MPG = 0 ,@BPP = 0 ,@MON = '' ,@ACTIVE = 1 ,@VALUE = 1"])

The variables which I need to get from my Excel workbook are @SCE = '117,118,148,151,152,159,163'
Prior to Power Query I built the statement in VBA
The variables are stored in a table on Sheet1 in the form of
B8 to B50 have these numbers
C8 to C50 are a description
D8 to D50 are a check against which if it is 'x' then select

BCD
7116FY14
8117FY15
9118FY16
10148FY17x
11156FY18x
12160FY19x
13163FY20

In the example above the source code needs to read
SQL:
= Sql.Database("SERVER", "DBNaame", [Query="EXEC stored_procedure @SCE = '148,156,160', @REG = '', @SBU = '20,64,69,63,67,68,93,65', @BUN = 0 ,@PRC = 0 ,@MPG = 0 ,@BPP = 0 ,@MON = '' ,@ACTIVE = 1 ,@VALUE = 1"])
because they have an x against them in column D

Anyone have any ideas
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Has anyone come acroos a web where you can paste your individual sql querys and have the website join them into one ?
 
Upvote 0

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top