SP with input parameters to disable and enable indexes

I need to build a stored proc script with input paramters to disable indexes and enable indexes of specific tables.
Parameter would be tablename,schemaname,a value input which will determine if it is for disabling index or enabling index
I will have a reference table which would hold the specific tables
Below is the ddl script and sample data for reference
USE [test]
GO
/****** Object:  Table [dbo].[TestingIndex]  DDL  Script Date: 01/27/2014 22:38:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TestingIndex](
[tablename] [varchar](30) NULL,
[schemaname] [varchar](10) NULL,
[Flag] [varchar](1) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
sample data
tablename
schemaname
Flag
tableabc
abc
y
tabledef
def
y
tableghi
ghi
y
All I want to do is disable all the indexes of the tables which are present in my reference table by looping through the reference tables.
Similarly I want to do enable all the indexes of the diabled table using the reference table
Any help would be appreciated and best way to do it thinking all pros n cons.
Mudassar

New code with changes
USE [TEST]
GO
/****** Object: StoredProcedure [dbo].[usp_indexes] Script Date: 1/28/2014 10:11:55 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_indexes1]
@ref reftable READONLY,
@input int
AS
BEGIN
---Declare variables
DECLARE @tblnm VARCHAR(30), @schnm VARCHAR(10), @flag BIT, @sql VARCHAR(MAX)
---Declare cursor
DECLARE cursor_index CURSOR
FOR SELECT tablename, schemaname, flag FROM @ref
--Open cursor
OPEN cursor_index
FETCH NEXT FROM cursor_index INTO @tblnm, @schnm, @flag
WHILE @@FETCH_STATUS = 0
BEGIN
if @input =1
BEGIN
SET @sql = 'ALTER INDEX ALL ON '+@schnm+'.'+@tblnm+' DISABLE '
print @sql
EXEC sp_execute @sql;
END
else
BEGIN
SET @sql = 'ALTER INDEX ALL ON '+@schnm+'.'+@tblnm+' REBUILD '
print @sql
EXEC sp_execute @sql;
ALTER INDEX ALL ON dbo.Test1 DISABLE
END
FETCH NEXT FROM cursor_index INTO @tblnm, @schnm, @flag
END
CLOSE cursor_index
DEALLOCATE cursor_index
END
GO
result when I execute it gives below message
(3 row(s) affected)
ALTER INDEX ALL ONdbo.Test1DISABLE
Msg 214, Level 16, State 2, Procedure sp_execute, Line 1
Procedure expects parameter '@handle' of type 'int'.
ALTER INDEX ALL ONdbo.Test3DISABLE
Msg 214, Level 16, State 2, Procedure sp_execute, Line 1
Procedure expects parameter '@handle' of type 'int'.
ALTER INDEX ALL ONdbo.Test4DISABLE
Msg 214, Level 16, State 2, Procedure sp_execute, Line 1
Procedure expects parameter '@handle' of type 'int'.
DECLARE @ref reftable
INSERT INTO @ref
SELECT * FROM testingindex
EXEC usp_indexes1 @ref,1
but when I go n check indexing status no tables  have been disabled using the below query it shows still enabled
select sys.objects.name as 'table',
sys.indexes.name as 'index',
is_disabled = case is_disabled
when '1' then 'disabled'
when '0' then 'enabled'
end
from sys.objects join sys.indexes
on sys.objects.object_id = sys.indexes.object_id
where sys.objects.name in('Test1','Test3','Test4' )
below are my table schema and index script (similar for 3 tables i m using for testing)
CREATE TABLE [dbo].[Test1](
[YEAR] [varchar](10) NULL,
[MONTH] [varchar](10) NULL,
[MONTH_VAL] [varchar](10) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
USE [TEST]
GO
/****** Object: Index [NonClusteredIndex-20140128-112203] Script Date: 1/28/2014 11:23:48 AM ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20140128-112203] ON [dbo].[Test1]
[YEAR] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
Mudassar

Similar Messages

  • Error when using Analytic view with Input Parameters

    Hi,
    I am trying to create an info space based on my Analytic view which has input parameters. The infospace is validated and indexed without any issue. However when I ran the view, I get an error (50011) as it is unable to fetch any results. I tried using an infospace based on Calculation view with input parameters and the explorer view works without any issue.
    Has anyone faced similar issues?
    We are using HANA SP 6 rev 67 and BI 4.0 SP 4.
    Also is there a way to enable input prompts for the users when they refresh the BO Explorer view? If not currently available is there any work around ?
    Thanks

    Hello George,
    I don't have any personalization set on the info space. Also I am using mapped Account in BI to connect to HANA. The confusing part is that it is able to validate the infospace with the input parameters and index it. However query does not return any results. I even tried running the same query which explorer sends to HANA in the SQL editor and there too the same results,the query does not return anything. The model does return data when I do a data preview and if accessed from other tools like AAO.
    Also when I use SSO connection to HANA, indexing of the infospace fails. Where can I see the error log?
    Thanks,

  • How to write a SQL query in SAP B1 2007 B with input parameters?

    How to write a SQL query in SAP B1 2007 B with input parameters, on execution of which will ask for some input value from the user and the values will be selected from a list such as item list?

    The syntax like
    SELECT * FROM OITM T0 WHERE T0.ItemCode = '[%0\]'
    Thanks,
    Gordon

  • How to write XSJS Select Query with input parameters

    Hello Experts,
    I am creating a xsjs file and in that file I am trying to write a Select Query based on a Calculation View
    I have tried it the following way:
    var query = 'SELECT TOP 100 \"Name\", \"Address\", \"City\", \"Country\" FROM \"_SYS_BIC\".\"Test.HL/AddressView\"'
        + 'WITH PARAMETERS(\'PLACEHOLDER\' = (\'$$P_Name$$\', \' Akhil \'),'
      + '\'PLACEHOLDER\' = (\'$$P_City$$\', \' Lucknow \'))';
    But it gives me the "Mixed spaces and tabs error".
    How should I write XSJS Select Query with input parameters?
    Regards,
    Rohit

    >But it gives me the "Mixed spaces and tabs error".
    Mixed spaces and tabs has nothing to do with the syntax of the statement. You used both spaces and the tab in the content - which JSLint doesn't like.  Remove the beginning spaces of each line and use only one or the other.
    The actual syntax of your statement doesn't look right.  The problem is that you are escaping the \ when you don't need to if you are using ' instead of " for your string.  You escape with \" in the first line but then escape with \' in the 2nd and 3rd line.  That is going to cause serious parsing problems with the command.

  • Questions on CDS Views with input parameters

    Dear Experts,
    1. Can we call a CDS View (or generated database view) with input parameters inside an AMDP? I am looking for something similar to the feature in HANA where we can consume calculation view with filters inside SQL Script?
    2. I understand we can next CDS Views, but how we can next (call) a CDS View with input parameters inside another CDS View?
    Thanks,
    Giri

    Hi Thomas,
    I get the below error that the CDS View's generated table function cannot take field from AMDP.
    I have a requirement to query the CDS View using 2 timestamps (start & end). So, in AMDP I have used the TIME_STAMP and try to pass it to the CDS View
    View code:
    define view Z_Ngi_Cag_A
    with parameters start_ts:abap.dec( 15, 0 ) , end_ts:abap.dec( 15, 0 )
    as select from table {
    resource_key
    where
    (begtstmp > $parameters.start_ts or endtstmp > $parameters.start_ts )
    and
    (begtstmp < $parameters.end_ts or endtstmp < $parameters.end_ts )
    I am calling using the below AMDP:
    DECLARE iv_start_date TIMESTAMP;
    DECLARE iv_end_date TIMESTAMP;
    SELECT CURRENT_TIMESTAMP INTO iv_start_date from dummy;
    SELECT ADD_DAYS(CURRENT_TIMESTAMP, 30) INTO iv_end_date from dummy;
    et_data =      SELECT * FROM ZMR_H_CA ( start_ts => iv_start_date, end_ts =>  iv_end_date );
    What could be wrong ? Is this not supported?
    Thanks,
    Giri

  • Call a Graphical Calc view with input Parameters from a Script Based Calc View

    Hi All.
    I am trying to call a graphical calculation view with input parameters from a script based calculation view as below but getting syntax error:
    SESSION_SAMPLE = SELECT SESSION_CREATE_DATE,SHA256,CA_MEASURE
                                 FROM "_SYS_BIC"."WILDFIRE/CV_SESSION_SAMPLE"
                                 WITH PARAMETERS  ('PLACEHOLDER' = ('$$IP_START_DATE$$',:START_DATE),
                                     'PLACEHOLDER' = ('$$IP_END_DATE$$',:END_DATE));
    START_DATE  and END_DATE are input parameters of the script based calculation view.
    Can anyone please help me with the correct syntax for accomplishing this?
    Thanks,
    Goutham

    Hi Gautham,
    One more option  what i would like you to try is the below option , here i have just changed the order of passing nothing else.
    SESSION_SAMPLE = SELECT SESSION_CREATE_DATE,SHA256,CA_MEASURE
                                 FROM "_SYS_BIC"."WILDFIRE/CV_SESSION_SAMPLE"
                                   ('PLACEHOLDER' = ('$$IP_END_DATE$$','$$END_DATE$$'),
                                  'PLACEHOLDER' = ('$$IP_START_DATE$$','$$START_DATE$$'))
    Regards,
    Vinoth

  • Calculated view with input parameters

    Hello there.
    I've created a calculated view with input parameters, which I am going to call  it  'VIEW_A'.
    This view has been working just fine.
    But now I have to create another calculated view and import the last one(VIEW_A) in a projection.
    But I got a error when trying to see the data content. 
    It says :
    Error: SAP DBTech JDBC: [2048]: column store error: search table error:  [6968] Evaluator: syntax error in expression string;expected TK_ID,parsing '"DT_DOC_MES_ANO" >= [here]and "DT_DOC_MES_ANO" <='
    At the 'Problems' panel it says the all the input parameters are unmapped.
    What Am I doing wrong?  Sorry but I am kind new at SAP world.

    http://scn.sap.com/message/15489475Hello Tiago,
    Could you please let me know if you're able to resolve your issue, I'm getting the similar error when I'm passing alpha numeric values as parameter via my SP.
    Thanks for your help in advance!
    Regards,
    Sathish

  • How to disable and enable a java bean area's visability?

    I have a large javabean area on my initial canvas when first dispalying my form.
    When I use the SHOW_CANVAS('canvas name') to display another canvas, everything looks fine except that the javabean from my previous canvas is still visible and covering up portions of this new canvas.
    So I tried using the set_property visible for the javabean area in the form and it only got rid of the surrounding edge of the javabean area.
    Last I made some set_custom_property values to send to the bean that would then use java calls to enable and disable the beans visability.
    But once the beans visibility was disabled in Java then it wouldn't come back after the calls to enable the visibility and refresh the bean were made through Java calls.
    Is there any other ways of disabling and enabling a java bean area's visability?
    Thanks,
    Michelle

    Hello,
    Maybe the bean is always display because of its particular paint() method ?
    Anyway, without any reflexion, I could suggest you to set the bean item width and height to 1 pixel when you don't want to display it. (Set_Item_Property)
    Francois

  • I recently had to disable and enable all add-ons on Firefox. Now when I google something, when I hover over the website preview and click 'cached' it won't highlight the key terms anymore. How can I fix this?

    I recently had to disable and enable all add-ons on Firefox. Now when I google something, when I hover over the website preview and click 'cached' it won't highlight the key terms anymore. How can I fix this?

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • GP and VC problem with input parameters

    Hi
    I have a problem with my GP dynamic approvals..
    I am trying to pass the parameters from one level to another level in GP using Visual COmposer screen with input and output parameters.
    When I see in NWA, I can see the ouput parameters of Screen1 is passed to input of Screen2 but I am not able to get the values in VC Screen.
    This scenario was working fine earlier.
    THe VC screen is same for all the approvals , I am doing dynamic approvals using predefined conditional callable  object and looping it.
    any suggestions..

    I have solved myself, I am sending html tags from one level to another level like <html></html> - these tags are not allowing VC screen to get all the parameters and they are blocked. I removed the tags, then I am able to get the parameters passed.

  • I installed AVG 2011 Free, and Firefox 4 today on a friends compouter. The AVG Safe Search Toolbar is not available, even after disabling and enabling the Add On. I use AVG 2011 full Licence with Firefox 4 at home no problems. How do I fix this please

    Works in IE no probs, Add On shows in Add On's List. AVG Safe Search Toolbar not available in toolbar lists.

    Because I am having issues with Norton Security Suite with the upgrade to Firefox 4.0.1, I have been dealing with that as well, with no success to-date. However, I did notice today when I was looking in my trash, an interesting thing occurred with the upgrade that MAY have something to do with the apps. in Facebook not working correctly now with Firefox.
    In my trash, there are several folders of 'Recovered Files'. Two of them are loaded with Internet Plugins for Facebook and were all dumped on May 1st, the day I upgraded to v. 4.0.1 Firefox and began having all my problems. For example, they are plugins like: plugin-cross domain.xml, plugin-gateway-1.php, plugin-102452128776.gz-72.json, just to name a few of them. Now, I am wondering if they were inadvertently removed during the upgrade process, or if they are in conflict with the new upgrade. Should I put them all back into Library -->Internet Plug-Ins to see if that resolves the problems? There are so many of them, I wish there was a way to mark them in some fashion in case I would have to remove them and not take the wrong ones out! Maybe there is a way I can color code them before I move them. I hate using 2 browsers!
    I notice that 2 other people have this problem but I don't see where they left any post. I really wish Norton, Firefox, and Facebook would get this ironed out. I never had a problem with anything until this and I don't like to spend all my time trying to troubleshoot something I don't understand! Anyway, thanks for listening.

  • Disable and enable on Apex 4.2.1 tabular form

    Hi,
    I have a requirement on Apex 4.2.1 tabular form where It gets rows dynamically based on the master record.
    when page loads for the first time all the rows on the tabular form should disable and based on check all rows it should enable all the rows
    or if I check particular row it should enable that row. is this possible with dynamic action. or else how can i achieve this ??
    Thanks

    user10755387 wrote:
    Hi,
    I have a requirement on Apex 4.2.1 tabular form where It gets rows dynamically based on the master record.
    when page loads for the first time all the rows on the tabular form should disable and based on check all rows it should enable all the rows
    or if I check particular row it should enable that row. is this possible with dynamic action. or else how can i achieve this ??
    You cannot disable them instead make them read-only, but the problem comes if you have any form controls like select lists because they are already read-only
    Create a dynamic action as follows:
    Event: Page Load
    True Action: Execute JavaScript Code
    Code:
    //replace the REGION_STATIC_ID with your tabular form's region static id
    $('#TF').find('.uReport.uReportStandard').find('tbody').find('td[headers!="CHECK$01"] > :input').attr("readonly", true).css("background-color", "#F2F2F2");
    $('td[headers="CHECK$01"] > input').click(function () {
         if ($(this).is(':checked')) {
              $(this).parent('td').parent('tr').find('td[headers!="CHECK$01"] > :input').attr("readonly", false).css("background-color", "");
         else {
              $(this).parent('td').parent('tr').find('td[headers!="CHECK$01"] > :input').attr("readonly", true).css("background-color", "#F2F2F2");
    });

  • Error while creating a BO Universe (using IDT) on top of SAP HANA Calculation View with Input Parameters

    Hi All..
          We are trying to create a Universe (using IDT-Version4.0) on top of the HANA Calculation view. The Calculation view has 4 input parameters, So
    in Universe side we have created the respective prompts. For the creation of derived table we have used the following code
    SELECT *
    FROM "_SYS_BIC"."<schema_name>.<CV_Calculation_View_test>"
    'PLACEHOLDER'=('$$IP_A$$','@Prompt(A)'),
    'PLACEHOLDER'=('$$IP_B$$','@Prompt(B)'),
    'PLACEHOLDER'=('$$IP_C$$','@Prompt(C)'),
    'PLACEHOLDER'=('$$IP_D$$','@Prompt(D)')
    While validating the above code we are getting an error.
    I have attached the snapshot of that error for your reference. Please find the attachment and help me in resolving it.
    Thanks in advance.

    Hello George,
    I don't have any personalization set on the info space. Also I am using mapped Account in BI to connect to HANA. The confusing part is that it is able to validate the infospace with the input parameters and index it. However query does not return any results. I even tried running the same query which explorer sends to HANA in the SQL editor and there too the same results,the query does not return anything. The model does return data when I do a data preview and if accessed from other tools like AAO.
    Also when I use SSO connection to HANA, indexing of the infospace fails. Where can I see the error log?
    Thanks,

  • REST Web Reference with Input Parameters

    I am using  APEX 4.2.0
    I was integrating with remote oracle database with API (Restful)
    it's working me fine from APEX Page items with username and password
    with static contents that located in the:
    Home >Application Builder >Application 179 >Shared Components >Web Service Reference> Edit
    Name
    URL
    Test
    View
    Updated By
    Updated
    Created By
    Created
    GAAS
    http://remotehost:port/api/registered
    username
    47 minutes ago
    in the region of:
    REST Input Parameters
    With the option of 
    Specified Body with Substitutions
    The content is located as static in the source item and I have copied to the below section:
    <?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
    <registerRequested>
        <requestType>register</requestType>
        <firstName>IBRA</firstName>
        <lastName>ADAM</lastName>
        <msisdn>699502112</msisdn>
    </registerRequested>
    So my question is how can I change the above static that I have received from remote side  into the input items
    Example
    :P95_FIRST_NAME
    :P95_LAST_NAME
    :P95_MSISDN
    Thanks in advance

    The APEX forum is here : Application Express
    I'm sure you'll get more help there.

  • Issue with Input Parameters & Variables

    Hello Gurus,
    I have a situation where, when the user enter “Parent Company”   say for ex: ABC, then the over all
    Result should filter by ‘ABC’, and then there is key figure column where I need to consider not equal to ABC and then sum the key figure.
    In HANA, here both variables and Input patemters are mutually exclusive. Is there any way that I can pass the value of the variable to the input parameters without writing the code in Analytical or calculation views.
    If it’s BW-bex, it was very straight forward, I can create the variable for parent company ‘ABC’, put it as global filter, so that whenever the user selects ‘ABC” it should display on ABC data in the out put.
    I can also use the same variable and crate calculated column in BEx and attach the variable to the key figure and say the sum the key figure but exclude the Parent company “ABC’.
    I have tried the projection view and try to put filter on it, but it did not work. My requirement is
    Whenever the user selects ABC, it should display only ABC data, only 10 records out of 100 records and for one key figure column; I need to aggregate but excluding the Parent company “ABC”.
    Can I pass the Variable value to input parameters without writing the code?
    Regards
    Ramakrishnan Ramanathaiah 

    How about the following:
    Assuming you have 2 characteristics (Plant and Parent company) and 1 KF (Net Sales).
    Now let's create a projection with Filter using Input parameter on Parent company (with user input value as ABC), which might give the output as:
    Plant
    comp
    Net Sales
    P1
    ABC
    10
    P2
    ABC
    5
    Now, let's create a second projection with the Calc KF "Net Sales calculated" with the formula as:
    if comp = $input_value$, then 0 else Net_Sales.. this way you can simulate the EXCLUDE functionality.
    Plant
    comp
    Net sales
    P1
    ABC
    0
    P1
    BCD
    15
    P2
    ABC
    0
    Now union both the projections with two diff KFs, Net Sales and Net Sales Calculated.
    Plant
    Net Sales
    Net Sales Calc
    P1
    10
    15
    P2
    5
    0
    Subsequent model depends on your reporting drilldown requirement. If you drilldown Parent company also in the rows, then you will see the split in the values.
    Please try this and let us know if it works or what other issues come up.. we can try resolving the issues..
    Ravi

Maybe you are looking for

  • How can I set a cross reference to a Picture

    Hello, I have a question regarding the new function: How can I set a cross reference (dont know the exact english name since I use the German version; in German: Querverweis) in Indesign CS4 to a picture? So far, I could only do it with a kind of wor

  • On an iPod Nano 2G, the iPod will not show in iTunes

    Using an iPod Nano 2 G, when I plug it into a Mac, the iPod will not show in iTunes. The iPod will charge, but will not sync. This happens across multiple Mac's, so the issue seems to be the Nano, not the computer(s). The iPod will actually show for

  • Missing Photo Gallery

    I've been working on a portfolio website for my girlfriend this past week, and even in iWeb its proving to be pretty tough. I've created a photo album for the site. However, when I publish and then view the published site, no album appears. Is there

  • Calling SQL*Loader from Forms

    Hi, I was wondering if anyone has called SQL*Loader from Forms? What I am wanting to do is use Oracle Forms as the interface where you can specify a file that you can import into the database and it will use a set control file. Push the import button

  • Creating Attribute in BO ?

    Hi Gurus, Iam trying to create the attribute(Funcenter in BO BUS0050), my logic is not working, i know i done a small mistake. plz help me. i want to fect the Funcenter from FMBL by Using FMAREA and DOCNR (Document number ) Plzzz  correct my ocde. GE