Need help in creating a view with Encryption for hiding the code used by the multiple users

Hi,
Can anyone help me out in creating view with encryption data to hide the stored procedure logic with other users.
I have create a stored procedure with encryted view but while running this manually temporary views are getting created, therefore the problem is if there are 500 entries then 500 temp views will get created.
Any solution to aviod creating temporary views, please refer my code below
USE [etl_validation]
GO
/****** Object:  StoredProcedure [dbo].[Pr_DBAccess_mod]    Script Date: 05/23/2014 12:53:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Pr_DBAccess_mod](@ETL_CONFIG_ID INT)
AS
BEGIN
DECLARE @openquery NVARCHAR(MAX),
 @DATABASENAME NVARCHAR(100),
 @HIERNAME NVARCHAR(100),
 @TABLENAME NVARCHAR(100),
 @SERVERTYPE NVARCHAR(100),
 @SERVERNAME NVARCHAR(100),
 @USERNAME NVARCHAR(100),
 @PASSWORD NVARCHAR(100),
 @ETL_CONFIG_IDN NVARCHAR(100);
 SET @ETL_CONFIG_IDN=CAST(@ETL_CONFIG_ID AS NVARCHAR);
 SET @TABLENAME='Department';
 SET @SERVERTYPE='SQL';
 SET @SERVERNAME ='192.168.31.176';
 SET @DATABASENAME='AdventureWorks2008R2';
 SET @HIERNAME = 'HumanResources';
 IF @SERVERTYPE='SQL'
 BEGIN
/*SET @openquery= 'SELECT * INTO ##TestTable
                 FROM OPENROWSET(''SQLNCLI'',''server=192.168.31.176;Trusted_Connection=yes;'','''+@query+''')'
SET @openquery=  'CREATE VIEW '+@TABLENAME+@ETL_CONFIG_IDN+
                 ' WITH ENCRYPTION AS SELECT * FROM OPENROWSET(''SQLNCLI'',''SERVER='+@SERVERNAME+';TRUSTED_CONNECTION=YES;'',''SELECT * FROM '+@DATABASENAME+'.'+@HIERNAME+'.'+@TABLENAME+''')'
SELECT @openquery
END
EXECUTE sp_executesql @openquery
END

Hi aa_rif,
According to your description and code message, you execute the sp_executesql statement in your stored procedure, it indeed create many views with a tablename and ETL_CONFIG_ID named. If you need not to use these temporary views, you can delete them when
it contains the tablename in one view name.  
In addition, if you want to create view with encryption in SQL Server, you can use directly the ENCRYPTION option to encrypt the T-SQL of a view in create view commands, for more information, see:
http://learnsqlserver.in/4/Create-View-With-Encryption.aspx. if not, you can descript more detail about requriements, so that more forum members can involve into the thread and help you
out. 
Regards,
Sofiya Li
Sofiya Li
TechNet Community Support

Similar Messages

  • Needs help to create a VIEW

    EXAMPLE data as under below;
    TABLE customer_transactions;
    there is 4 columns
    cust_id type_of_transaction trasaction_no date_of_transactions amount
    1 INVOICE INV01 1/6/2002 9500
    1 DEBIT NOTE DB01 2/8/2002 1050
    1 RECEIPT R01 2/8/2002 10000
    1 INVOICE INV02 5/9/2002 2500
    1 CREDIT NOTE CR01 2/9/2002 70
    receipt_master
    rec_no rec_date amount
    R01 2/8/2002 10000
    receipt_details(child table to receipt_master)
    rec_no againest_voucher_type voucher_no
    R01 INVOICE INV01
    R01 DEBIT NOTE DB01
    i need a to create a VIEW like below
    custid total_due due0_30days due30_60days due60_90days due_above_90days
    1 2980 2430 550 0 0
    im facing critical situation with receipts which i have to deduct againest some invoices and
    debitnotes.
    now at the moment im using a long pL/SQL program to do this which i taking so much time. i saw a
    advise few days back to create view for the above report. i tried to in my way. but no success.
    please advise me on my issue.

    Not certain how you determine when to subtract, however you might be able to use DECODE.
    select A.Cust_Id, max(B.due_0_30), max(C.Due_31_60), max(D.Due_61_90), max(E.Due_Above90)
      from cust_trans A,
              (select Cust_ID, Sum(Decode(Trans_Type,
                                                                       'INVOICE', Amount,
                                                                       'CREDIT NOTE', (Amount*-1), 
                                                                       'DEBIT NOTE', Amount,
    --                                                                   'RECEIPT', (Amount*-1),  -- THIS IS WHERE I'M NOT CERTAIN
                                                                        Amount) ) Due_0_30
                     from Cust_trans
                     where Trans_dt between trunc(sysdate-30) and trunc(sysdate)
                    group by Cust_Id ) B,
                  (select Cust_ID, Sum(Decode(Trans_Type,
                                                                         'INVOICE', Amount,
                                                                         'CREDIT NOTE', (Amount*-1),
                                                                         'DEBIT NOTE', Amount,
    --                                                                   'RECEIPT', (Amount*-1),  -- THIS IS WHERE I'M NOT CERTAIN
                                                                         Amount) ) Due_31_60
                    from Cust_trans
                    where Trans_dt between trunc(sysdate-60) and trunc(sysdate-31)
                   group by Cust_Id ) C,
               (select Cust_ID, Sum(Decode(Trans_Type,
                                                                        'INVOICE', Amount,
                                                                        'CREDIT NOTE', (Amount*-1),
                                                                        'DEBIT NOTE', Amount,
    --                                                                   'RECEIPT', (Amount*-1),  -- THIS IS WHERE I'M NOT CERTAIN
                                                                         Amount) ) Due_61_90
                    from Cust_trans
                    where Trans_dt between trunc(sysdate-90) and trunc(sysdate-61)
                   group by Cust_Id ) D,
                (select Cust_ID, Sum(Decode(Trans_Type,
                                                                        'INVOICE', Amount,
                                                                        'CREDIT NOTE', (Amount*-1),
                                                                        'DEBIT NOTE', Amount,
    --                                                                   'RECEIPT', (Amount*-1),  -- THIS IS WHERE I'M NOT CERTAIN
                                                                         Amount) ) Due_Above90
                    from Cust_trans
                    where Trans_dt < trunc(sysdate-90)
                   group by Cust_Id ) E
    WHERE A.Cust_Id = B.Cust_Id(+)
      AND A.Cust_Id = C.Cust_Id(+)
      AND A.Cust_Id = D.Cust_Id(+)
      AND A.Cust_Id = E.Cust_Id(+)
    group by A.Cust_ID

  • Need help in Creating DB manually with OFA

    Hi,
    I want to create database in 10g manually and for this purpose
    I need help.
    since we can use OFA for storing Control files, and redolog file
    and datafile by describing them in Create database command but
    how to store any instance related file like spfile, pfile or network
    related file.
    once the oracle 10g database software is installed then if we want
    to create database then how can we separate the database file and
    all other instance files from software binaries because I've noted
    that creating database with DBCA create all instance files along with
    binary files of the software although DBCA give you option of creating
    database related file in some other location/directory.
    kindly help me in this I want to achieve above task in compliance with
    OFA
    Thanks and Regards,
    D.Abbasi

    Abbasi wrote:
    Hi,
    I want to create database in 10g manually and for this purpose
    I need help.
    since we can use OFA for storing Control files, and redolog file
    and datafile by describing them in Create database command but
    how to store any instance related file like spfile, pfile or network
    related file.
    once the oracle 10g database software is installed then if we want
    to create database then how can we separate the database file and
    all other instance files from software binaries because I've noted
    that creating database with DBCA create all instance files along with
    binary files of the software although DBCA give you option of creating
    database related file in some other location/directory.
    kindly help me in this I want to achieve above task in compliance with
    OFA
    Thanks and Regards,
    D.AbbasiTHe OFA spec (as best I recall) states that one of the levels of directory for all of your data files will be the db name. So if you name your database 'orcl', every file system in which you keep any files related to 'orcl' will be in a directory name 'orcl'.
    As for what happend when you created your db. Oracle will default to putting things in the Oracle home structure because that's the only thing he can guarantee will be there. But you had the option (indeed, the obligation) to override these defaults.
    BTW, when using dbca, if you chose any of the pre-canned database types, the database will be created by doing a restore from a pre-canned backup. If you chose 'custom' database, the database will be created by way of a CREATE DATABASE script. It would be instructive time well spent for you to go through dbca and select 'custom database', pay attention to all of the options as you work through, then at then end, deselect "create database" and select "generate scripts". Do the same for one of the pre-defined database types. Then study the scripts generated by each method.
    Edited by: EdStevens on Aug 16, 2009 8:46 PM

  • Need help on creating a button with additional drop down menu

    Hi,
    I need to have a button with additional menu as we see in IE, please help me how can i do that. I want the button to be displayed normally with an additional arrow on the right side when clicked on it shows pop up menu. Please let me know if the solution has already there in the forum. I searched and couldn't get one .. :(

    Hey there buddy.
    Try this:
    http://www.koders.com/java/fid20361AB8C305DE9B9110DE90F2154FC43AA0E57C.aspx
    Jason.

  • Need help in creating table in crystal report for visual studio 2010

    Since there is no table support in crystal report,how can I create a table in crystal report for visual studio 2010?
    I have a datatable and I need to show that in crystal report in table structure.
    I have tried using lines and boxes to generate the table but it is not working perfectly.
    How can I export the report in excel format in read/write mode saving all the formatting in the report

    Hi,
    Check sample codes from following:
    http://wiki.sdn.sap.com/wiki/display/BOBJ/CrystalReportsSDKSampleApplications
    You can download the [Developer's Guide|http://help.sap.com/businessobject/product_guides/boexir31/en/crsdk_net_dg_12_en.chm] & [API Guide|http://help.sap.com/businessobject/product_guides/boexir31/en/crsdk_net_apiRef_12_en.chm]
    Thanks,
    Saurabh

  • Creating Materialized View with the Distinct key word

    Hi
    I need help to create Materialized View with the Distinct key word.
    my query is
    select distinct col1, col2 from t1;
    is there any alternate of DISTINCT because I can not refresh the MV as fast on demand if I am using it and Fast on Demand is a must for me.

    hi
    check out this link
    http://download-west.oracle.com/docs/cd/B12037_01/server.101/b10736/basicmv.htm#i1007299
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/intro.htm#sthref183
    hope this helps
    CHeers

  • Help to creating a Toshiba recovery disc for portege r200

    Hi people, I have lost my CD´s from my computer. And I need to re-install XP on my computer. I need help to creating a disc with XP for install on my computer r200. every time I tray to install XP I get erro " the time start format my disk, the instalion stop and say to check the hard drive" 

    Better to acquire the recovery discs. Which Portege R200? What country?
    -Jerry

  • Creating a view with a primary key

    I want to create a view with a defined primary key. I understand
    the view is created within a select statement, but do not
    understand how you would define a particular field as a primary
    key in the view. Also if your select statement attempts to build
    the view and has duplicate keys in the select result set, what
    would happen when the duplicate key is found? Would it just not
    include the duplicate key in the view?
    Thanks in advance for your help.
    -Pat

    I have a rather difficult problem with duplicate invoice numbers
    contained in unique records. In other words I have many records
    that appear as follows:
    3593, 0004009090, CUSTOMER, TAX, 20000117,014011976-01
    4411, 0004009090, CUSTOMER, TAX, 20000718,014011976-01
    The last field is invoice number '014011976-01' In my case I am
    building a flat file using UTL_FILE for loading into SAP
    Business Warehouse. In SAP I need to have Invoice number as a
    key in which case I can't have duplicate invoice numbers. All
    the SQL I have tried to date returns a large amount of records
    similar to the above records. I am selecting these records from
    4 different schemas which represent 4 different companies. I
    realize the data is the problem and that the vendor of the
    product I am working with should not allow records with
    duplicate invoice numbers, but I have to get the data loaded as
    that is what they want and are paying for. So back to my View. I
    was hoping to create a view and be able to work in the view to
    remove duplicate records prior to writing them to a file. Any
    suggestions are welcomed.
    Thanks
    -Pat

  • Pls help in creating cluster view

    Pls help in creating cluster view
    regards
    jindow

    Hi,
    Please try this and use BSEG as an example.
    1. Go to SE12.
    2. Enter BSEG
    3. Click Display button
    4. Go to Delivery and Maintenance' tab.
    5. You should be able to see Pool/cluster RFBLG.
    6. Double click RFBLG and then click Where-Used list button (CTRLSHIFTF3).
    7. Select Table option and click Execute button.
    8. System will show all the table that belong to this pool/cluster.
    For Pool/Cluster REGUC, it is only used in table REGUP.
    Look at the below link
    Re: Define view for cluster table?
    Regards,
    Priyanka.

  • Help! How do I create a document with an imported PDF in 300dpi using a FOGRA27 colour profile?

    I am a new Indesign user and I have been working with GIMP for the last year creating single colour print-ready PDFs. But now I need to create a document with a FOGRA27 CMYK colour profile and a resolution of at least
    How do I create a document with an imported PDF in 300dpi using a FOGRA27 colour profile?
    I can import the PDF by creating a new document and finding the PDF in places, but it's bad quality.
    The only colour profile I can find under View - Proof Setup is FOGRA39, but I need FOGRA27!
    Help help help, I need to get these files printed in two days!
    Thanks so much..
    xx

    Proof Colors doesn't change the file's color management, it just lets you see what the color values would look like if they are printed unchanged on different output devices. If you want to actually convert the color from one CMYK space to another, it's probably better to do that in Acrobat—Tools>Print Production>Convert Colors.
    There's very little difference between Fogra27 and Fogra39—Fogra27 allows more total ink 350 vs. 330.
    There's nothing you can do to improve the quality of low res images

  • How to create a view with parameters; read the documentation but nothing!

    Hello!
    I'm new to the Oracle world but together with my coworkers we need to very quickly study Oracle to figure out whether we'll add Oracle to our list of supported databases or not.
    Question: How do I create a view with parameters?
    I've read the documentation but I could not find this! I found the sql syntax to create a view but no parameters whatsoever...
    I have found on the web some very complicated way of doing this, but doesn't Oracle support Views with parameters?
    The goal here is to return a recordset, don't forget, so,please don't speak about stored procedures unless you are going to tell me how to get a recordset out of a stored procedure! ;)
    Thanks for all your help and attention!
    Jorge C.

    You can set up a parameterized view via context as follows:
    1. Set up a procedure to set your context values:
    create or replace procedure p_set_context (p_context IN VARCHAR2,p_param_name IN VARCHAR2,p_value IN VARCHAR2)
    as
    BEGIN
    sys.dbms_session.set_context(p_context,p_param_name,p_value);
    END;
    2. Create your context using the procedure you just created
    create or replace context my_ctx using p_set_context
    3. This is the test table I'll use
    create table my_table(col1 number)
    and populate it:
    begin
    for v_index in 1..10
    loop
    insert into my_table values(v_index);
    end loop;
    end;
    and the view that will be parameterised
    create or replace view v_my_table as select col1 from my_table where col1 between sys_context('my_ctx','start_range') and sys_context('my_ctx','end_range')
    4. Now set the parameters using the procedure above.
    begin
    p_set_context('my_ctx','start_range','1');
    p_set_context('my_ctx','end_range','5');
    end;
    5. Selecting from my_table will give you 1 to 10 (no surprise there :-) )
    selectng from v_my_table will give you 1 to 5
    You can use the context to set formats etc using the same principle. A common gotcha to watch for is trying to set the context directly using DBMS_SESSION.SET_CONTEXT instead of creating a procedure. This belongs to SYS and SYS won't have the privileges to set your context so you get an insufficient privileges result leading to much headscratching and unnecessary grants (at least that's my understanding of it).
    Sorry Jorge, as you're new to Oracle I should also have pointed out for completeness sake, that you can change the parameters at any time through recalling the p_set_context, for example, following on from above, after your "select * from v_my_table" and seeing 1 to 5, you could then do
    begin
    p_set_context('my_ctx','start_range','3');
    end;
    and when you requery 'Select * from v_my_table' you will now see rows 3 to 5.
    Bit of a simplistic example, but you can see how easy it is. :-)
    Message was edited by:
    ian512

  • Create a View with Aggregation Function (COUNT)

    I've been looking up and down for a way to create a view with a few basic fields and some other fields containing aggregation function.
    For instance:
    To display a view that contain all the Contract Agreement and the corresponding count of the PO releases.
    Agreement Nbr, Total PO releases
    I need this view so that I can create a search help with this view.
    I found something about the "CREATE VIEW" statement, but I don't have any idea how to use it.
    Any helps toward this matter is very much appreciated, thanks.

    Hello Aldern
    I guess you have read about the SQL statement "CREATE VIEW". When we create a view in the dictionary this SQL statement is finally called to create the view on the DB. Thus, since we do not have any aggregation options in views you cannot achieve what you want using views.
    The solution for your problem is to create a <b>search help</b> having a <b>search help exit</b>. Within the exit you can do your aggregation functions and add these values to the displayed search help data.
    Regards
      Uwe

  • Help to create Materialized View that has timestamp conversion

    I need help creating materialized view with timestamp conversion between GMT to LocalTime.
    Feel free to make any comments.
    Thanks in advance.
    jon joaquino;)

    Here is one way.
    1. Alter the table hist_table and add a new column pdt_timestamp.
    2. Update the new column using the function 'new_time'
    For example,
    Update hist_table
    set pdt_timestamp = new_time(gmt_timestamp,'GMT','PDT');
    3. create a materialized view log on the table 'hist_table' using the syntax
    create materialized view log on hist_table
    with primary key, rowid, sequence;
    4. create a materialized view now using the syntax:
    (You have to specify your own storage numbers and tablespace name)
    create materialized view mview_hist_table
    pctfree 0 tablespace mymview
    storage (initial 16k next 16k pctincrease 0)
    build immediate
    refresh fast on commit
    as select uid,gmt_timestamp,pdt_timestamp
    from hist_table;
    Please test on your test instance before doing it on production. I have tested this on Oracle 10g for Windows 2000. I assumed that column 'uid' is the primary key on the table. I hope this helps.
    **********************************************************

  • Need Help to create new screen for RF Sapconsole

    Hi Guru's
    I'm new on RF (but some years in ABAP) since last week.
    I need help to create new screens for RF (SAPLLMOB).
    Can someone explain me the procedure to create screen (with ABAP code after) or perhaps someone have an exemple (simple or not) ?
    I have to develop 2 new screens with really few time.
    And, another subsidiary question :
    how SAP can transfert information between the flash gun and the screen i have developped.
    Is there some code to add to enable this functionality or it is include in SAPLLMOB on standard fields ????
    It's a new strange world for me today...
    Many thanks to everyone who can explain me
    Alain

    hi,
    I am facing this problem as well. Is there any reference to create the new screen?
    Hope someone can help! Thanks!
    Regards,
    Darren

  • Need help in creating a chart from 3 datasets

    Need help in creating a chart in SSRS from 3 datasets
    Can someone help me in creating a chart from 3 datasets, however datasource is same.

    Thank you Olaf...
    could anyone help me in using union all with the below
     WITH a AS (
    SELECT
    clientid,
    DATEPART(year, row_date) AS 'Year',
    DATEPART(month, row_date) AS 'Month',
        value ,
        CASE metricid WHEN 16 THEN 'FCR' ELSE 'Cases' END AS metric
    FROM XXXXXX AS V
    WHERE metricid IN (16, 11)
    AND row_date BETWEEN '2012-01-01' AND '2014-10-01'
    AND value IS NOT NULL)
    , b AS (
    SELECT     clientid ,
        Year ,
        Month ,
        value AS 'Cases',
        metric 
    FROM a
    WHERE metric = 'cases')
    , c AS (
    SELECT     clientid ,
        Year ,
        Month ,
        value AS 'FCR',
        metric  
    FROM a
    WHERE metric = 'FCR')
    , d AS (
    SELECT b.YEAR, b.MONTH, c.FCR, b.Cases 
    FROM b INNER JOIN c 
    ON c.clientid = b.clientid
    AND c.[YEAR] = b.[year] 
    AND c.[month] = b.[month]
    WHERE c.fcr <> 0 AND b.cases <> 0
    ,E AS (
    SELECT [Year], [Month], SUM(FCR) AS FCR, SUM(Cases) AS Cases
    FROM d
    GROUP BY [Year], [Month])
    select YEAR, MONTH, 
    CASE MONTH 
    WHEN 1 THEN 'Jan'
    WHEN 2 THEN 'Feb'
    WHEN 3 THEN 'Mar'
    WHEN 4 THEN 'Apr'
    WHEN 5 THEN 'May'
    WHEN 6 THEN 'Jun'
    WHEN 7 THEN 'Jul'
    WHEN 8 THEN 'Aug'
    WHEN 9 THEN 'Sep'
    WHEN 10 THEN 'Oct'
    WHEN 11 THEN 'Nov'
    WHEN 12 THEN 'Dec'
    END AS MonthName
    ,e.FCR AS FCRCases
    ,e.Cases AS TotalCases
    ,CASE 
    WHEN [month] IN (11, 12, 1) THEN 1
    WHEN [month] IN (2, 3, 4) THEN 2
    WHEN [month] IN (5, 6, 7) THEN 3
    WHEN [month] IN (8, 9, 10) THEN 4
    END AS 'Quarter'
    --,CONVERT(DECIMAL(18, 2),(e.FCR/e.Cases)*100) AS FCRRaw
    from e
    order by YEAR, MONTH
    **************2nd query*************
    WITH a AS (
    SELECT
    clientid,
    DATEPART(year, row_date) AS 'Year',
    DATEPART(month, row_date) AS 'Month',
        value, 
        CASE metricid WHEN 56 THEN 'numerator' ELSE 'denominator' END AS metric
    FROM XXXXXXX.[Values] AS V
    WHERE metricid IN (56, 10)
    --WHERE metricid IN (11,16)
    AND row_date BETWEEN '2013-10-01' AND '2014-02-01'
    AND value IS NOT NULL)
    , b AS (
    SELECT     clientid ,
        Year ,
        Month ,
        value AS 'numerator',
        metric
    FROM a
    WHERE metric = 'numerator')
    , c AS (
    SELECT     clientid ,
        Year ,
        Month ,
        value AS 'denominator',
        metric
    FROM a
    WHERE metric = 'denominator')
    , d AS (
    SELECT b.YEAR, b.MONTH, c.denominator, b.numerator 
    FROM b INNER JOIN c 
    ON c.clientid = b.clientid
    AND c.[YEAR] = b.[year] 
    AND c.[month] = b.[month]
    WHERE c.denominator <> 0 AND b.numerator <> 0
    , e AS (
    SELECT [Year], [Month], SUM(numerator) AS numerator, SUM(denominator) AS denominator
    FROM d
    GROUP BY [Year], [Month]
    SELECT *, 
    CASE 
    WHEN [month] IN (11, 12, 1) THEN 1
    WHEN [month] IN (2, 3, 4) THEN 2
    WHEN [month] IN (5, 6, 7) THEN 3
    WHEN [month] IN (8, 9, 10) THEN 4
    END AS 'Quarter'
    FROM e
    ORDER BY 1,2
    ******************3rd query**************
    WITH a AS (
    SELECT --L.[LocationGroupId],
    -- T.locationid,
    -- T.AccountId,
    TR.datestamp,
    /*Convert(NVARCHAR, DatePArt(year, TR.datestamp)) + '-' + Convert(NVARCHAR, DatePArt(month, TR.datestamp)) + '-01'*/ 
    TR.Period AS ValueDate,
    CASE WHEN TR.TargetResultState = 0 THEN 0 WHEN TR.TargetResultState = 1 THEN 1 WHEN TR.TargetResultState = 2 THEN 1 ELSE 0 END AS Met,
    CASE WHEN CONVERT(DATE, Convert(NVARCHAR, DatePArt(year, TR.datestamp)) + '-' + Convert(NVARCHAR, DatePArt(month, TR.datestamp)) + '-01') > T.Startdate AND CONVERT(DATE, Convert(NVARCHAR, DatePArt(year, TR.datestamp))
    + '-' + Convert(NVARCHAR, DatePArt(month, TR.datestamp)) + '-01') < T.Enddate THEN 1 ELSE 0 END AS ActiveTarget
    FROM XXXXXX AS TR
    INNER JOIN dbo.Target T ON TR.TargetID = T.ID
    --INNER JOIN dbo.Location L ON T.Locationid = L.Id
    WHERE --locationid <> - 1 AND 
    TR.Period IN ('201306', '201307', '201308', '201309', '201310', '201311', '201312', '201401'))
    select ValueDate, SUM(Met) AS Met, Count(ActiveTarget) AS ActiveTargets,
    right(ValueDate,2) as Month
    ,left(ValueDate,4) as Year
    ,CASE 
    WHEN right(ValueDate,2) IN (11, 12, 1) THEN 1
    WHEN right(ValueDate,2) IN (2, 3, 4) THEN 2
    WHEN right(ValueDate,2) IN (5, 6, 7) THEN 3
    WHEN right(ValueDate,2) IN (8, 9, 10) THEN 4
    END AS 'Quarter'
    from a
    group by ValueDate
    order by ValueDate

Maybe you are looking for