Wednesday, November 9, 2016

changing system global settings


(change decimal format to use .(decimal) if using , (comma)


                //   // string v1 = _objValue.ToString().Replace('.', ',');

                //   System.IFormatProvider cultureUS =
                //new System.Globalization.CultureInfo("en-US");

                //   string CultureName = Thread.CurrentThread.CurrentCulture.Name;
                //   CultureInfo ci = new CultureInfo(CultureName);

                //   if (ci.NumberFormat.NumberDecimalSeparator != ".")
                //   {
                //       // Forcing use of decimal separator for numerical values
                //       ci.NumberFormat.NumberDecimalSeparator = ".";
                //       Thread.CurrentThread.CurrentCulture = ci;

 //lbl.Text = String.Format(_scheduleCellProperties.format, Double.Parse(_objValue.ToString(), cultureUS));


OR

  <globalization uiCulture="en-US" culture="en-US" requestEncoding="utf-8" responseEncoding="utf-8" enableClientBasedCulture="false"/>

Tuesday, October 25, 2016

Friday, October 7, 2016

Get all selected items from checkbox



EX 1:


 List<ListItem> selected = chk_SEZ_Fields.Items.Cast<ListItem>()
    .Where(li => li.Selected)
    .ToList();


Ex 2:


List<ListItem> selected = new List<ListItem>();
foreach (ListItem item in CBLGold.Items)
    if (item.Selected) selected.Add(item);
If you just want the ListItem.Value:


Ex :3 

List<string> selectedValues = CBLGold.Items.Cast<ListItem>()
   .Where(li => li.Selected)
   .Select(li => li.Value)
   .ToList();


if you want yo add to a list on buttonclick

private void btn_Click(object sender, EventArgs e)
{
    for (int i = 0; i < chBoxListTables.Items.Count; i++)
    {
          if (chBoxListTables.GetItemChecked(i))
        {
            string str = (string)chBoxListTables.Items[i];
            MessageBox.Show(str);
        }
    }
}

read the list and check the items on checkbox list on values
where Selected is the list of string with items

 for (int i = 0; i < selected.Count; i++)
            {
                if (selected[i].ToString() == "Coega Industrial Development Zones")
                    CheckBoxList1.Items[0].Selected = true;
                if (selected[i].ToString() == "Dube Trade Port IDZ")
                    CheckBoxList1.Items[1].Selected = true;

            }



check if the list contains specific value


   if (selected.Any(t => t.Text == "Other"))
            { TextBox1.Text = "test"; }
            else

                TextBox1.Text = "123";

Tuesday, October 4, 2016

check version of SQL running on server

select serverproperty('Edition')

select serverproperty('EditionID')



-1253826760 = Desktop
-1592396055 = Express
-1534726760 = Standard
1333529388 = Workgroup
1804890536 = Enterprise
-323382091 = Personal
-2117995310 = Developer
610778273 = Enterprise Evaluation
1044790755 = Windows Embedded SQL
4161255391 = Express with Advanced Services

Monday, October 3, 2016

show/ hide a TabPage in a ASPxPageControl

MyTabControl.TabPages[0].PageVisible = false;



 ASPxPageControlTab.TabPages.FindByName("TabPageTest1").Visible = false; 

Monday, September 26, 2016

select record in variable SQL

DECLARE @var1 varchar(30)  
SELECT @var1 = 'Generic Name'  
SELECT @var1 = ((SELECT top 10 Client_account_number FROM #TempTable1))  
SELECT @var1 AS 'account_number' ;

Generic script for selecting columns from result of stored proc

CREATE PROCEDURE SampleSP
AS
SELECT 1 AS Col1, 2 AS Col2
UNION
SELECT 11, 22
GO


CREATE TABLE #TempTable (Col1 INT, Col2 INT)
GO
INSERT INTO #TempTable
EXEC SampleSP
GO

SELECT *
FROM #TempTable
GO

DROP TABLE #TempTable
DROP PROCEDURE SampleSP
GO

Friday, September 16, 2016

TFS Locking issue


Files with .dll extension as well as other extensions like .exe, .doc, .docx, etc. are automatically locked because (as mentioned) here they cannot be merged.
If you want to disable the automatic lock and allow these files to go through gated check-in, follow the steps below:
  1. Log in to your build server.
  2. Open visual studio.
  3. In team explorer, log into your team project.
  4. Go to "Settings".
  5. Under "Team Project Collection", select "Source Control".
  6. Set "File Merging" property to "Disabled" for any file extension you don't want to be automatically locked.

Friday, September 9, 2016

SQL bulk insert sample

USE TestData
GO
CREATE TABLE CSVTest
(ID INT,
FirstName VARCHAR(40),
LastName VARCHAR(40),
BirthDate SMALLDATETIME)
GO

BULK
INSERT CSVTest
FROM 'F:\naiki_DB\mike\cvtest.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
--Check the content of the table.
SELECT *
FROM CSVTest
GO
--Drop the table to clean up database.
DROP TABLE CSVTest
GO

Monday, September 5, 2016

javascript sample from aspx.cs page


Printing from aspx.cs page

imgBtnPrint.Attributes.Add("onclick", "window.print();");

alert box from aspx.cs page

Response.Write("<script>alert('Hello');</script>");
button that directly prints a document via website:

<input type="button" value="Print" onclick="window.print();" />

or

<asp:button id="button1" runat="server" onclientclick="window.print(); return false;" text=Print" />

Another sample
  string popupScript = "<script language='javascript'>" + "window.open('frmLogin.aspx" + "', 'PasswwordExpiryWarning', " + "'width=430, height=318, menubar=no, resizable=no')" + "</script>";
 ClientScript.RegisterStartupScript(popupScript.GetType(), "Warning", popupScript);



btn cancle (on popup window):
btnCancel.Attributes.Add("onClick", "javascript:window.close();");














Friday, September 2, 2016

dynamically creating html table and binding to table in aspx page

aspx page code


 <table id="tblCTC_Data" runat="server">
                            <tr id="tdrCTCData_Header">
                                <td runat="server">Description fo Class Shares
                                </td>
                                <td runat="server">(a) Immediately before 1 January 2011
                                </td>
                                <td runat="server">(b) Where the company became a resident since 1 January 2011
                                </td>
                                <td runat="server">Add Considiration received or accrued for the issue of shares by the company
                                </td>
                                <td runat="server">Deduct amount transferred to holders of shares
                                </td>
                                <td runat="server">Deduct reduction as a result of the application of s42
                                </td>
                                <td runat="server">Deduct reduction as a result of the application of s44
                                </td>
                                <td runat="server">Deduct reduction as a result of the application of s46
                                </td>
                                <td runat="server">Balance of contributed tax capital at the end of the assesment
                                </td>
                            </tr>
                        </table>



aspx.cs page code


            tblCTC_Data.Rows.Clear();
            HtmlTableRow headerRow = new HtmlTableRow();
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Description fo Class Shares" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "(a) Immediately before 1 January 2011" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "(b) Where the company became a resident since 1 January 2011" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Add Considiration received or accrued for the issue of shares by the company" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Deduct amount transferred to holders of shares" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Deduct reduction as a result of the application of s42" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Deduct reduction as a result of the application of s44" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Deduct reduction as a result of the application of s46" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Balance of contributed tax capital at the end of the assesment" });

            foreach (HtmlTableCell c in headerRow.Cells)
            {
                c.Style.Add("font-weight", "bold");
            }

            tblCTC_Data.Rows.Add(headerRow);

            if (_rootCustomer.ReturnDetail.CorporateIncomeTaxReturn.CompanyDetails.ContributedTaxCapitalDetails.Count > 0)
            {
                foreach (CorporateIncomeTaxReturnStructureCompanyDetailsContributedTaxCapitalDetail xDataTable in
                _rootCustomer.ReturnDetail.CorporateIncomeTaxReturn.CompanyDetails.ContributedTaxCapitalDetails)
                {
                    HtmlTableRow newRow = new HtmlTableRow();
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ShareClassDescription.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.Before1January2011Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.After1January2011Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ConsiderationReceivedForShareIssueAmt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.TransferredToHoldersAmt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ReductionApplicationS42Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ReductionApplicationS44Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ReductionApplicationS46Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.BalanceEndOfYearAmt.ToString() });
                    tblCTC_Data.Rows.Add(newRow);
                }

            }





same code for asp.net table

.aspx page

  <asp:Table ID="tblCTC" runat="server" Width="794px" BorderStyle="Solid" BorderWidth="3px">
                <asp:TableRow ID="thrCTC_Description" runat="server" BackColor="Gray" ForeColor="White">
                    <asp:TableCell Font-Size="XX-Small" ID="thcCTC_Description" runat="server" ColumnSpan="2">
                        Contributed Tax Capital
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow ID="tdrCTC_CTCDetails_GrossIncomeAmt" runat="server" Width="794px">
                    <asp:TableCell Font-Size="XX-Small">
                        <asp:Table runat="server" ID="tblCTC_Data">
                            <asp:TableRow ID="tdrCTCData_Header" runat="server">
                                <asp:TableCell>Description fo Class Shares</asp:TableCell>
                                <asp:TableCell>(a) Immediately before 1 January 2011</asp:TableCell>
                                <asp:TableCell>(b) Where the company became a resident since 1 January 2011</asp:TableCell>
                                <asp:TableCell>Add Considiration received or accrued for the issue of shares by the company</asp:TableCell>
                                <asp:TableCell>Deduct amount transferred to holders of shares</asp:TableCell>
                                <asp:TableCell>Deduct reduction as a result of the application of s42</asp:TableCell>
                                <asp:TableCell>Deduct reduction as a result of the application of s44</asp:TableCell>
                                <asp:TableCell>Deduct reduction as a result of the application of s46</asp:TableCell>
                                <asp:TableCell>Balance of contributed tax capital at the end of the assesment</asp:TableCell>
                            </asp:TableRow>
                        </asp:Table>
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>




aspx.cs page code:

    tblCTC_Data.Rows.Clear();
            //HtmlTableRow headerRow = new HtmlTableRow();
            System.Web.UI.WebControls.TableRow headerRow = new System.Web.UI.WebControls.TableRow();
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Description fo Class Shares" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Description fo Class Shares" });


            //headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Description fo Class Shares" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "(a) Immediately before 1 January 2011" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "(b) Where the company became a resident since 1 January 2011" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Add Considiration received or accrued for the issue of shares by the company" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Deduct amount transferred to holders of shares" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Deduct reduction as a result of the application of s42" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Deduct reduction as a result of the application of s44" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Deduct reduction as a result of the application of s46" });
            headerRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = "Balance of contributed tax capital at the end of the assesment" });

            foreach (HtmlTableCell c in headerRow.Cells)
            {
                c.Style.Add("font-weight", "bold");
            }
            //tblCTC_Data.Rows.Add()
            tblCTC_Data.Rows.Add(headerRow);

            if (_rootCustomer.ReturnDetail.CorporateIncomeTaxReturn.CompanyDetails.ContributedTaxCapitalDetails.Count > 0)
            {
                foreach (CorporateIncomeTaxReturnStructureCompanyDetailsContributedTaxCapitalDetail xDataTable in
                _rootCustomer.ReturnDetail.CorporateIncomeTaxReturn.CompanyDetails.ContributedTaxCapitalDetails)
                {

                    System.Web.UI.WebControls.TableRow newRow = new System.Web.UI.WebControls.TableRow();
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.ShareClassDescription.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.Before1January2011Amt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.After1January2011Amt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.ConsiderationReceivedForShareIssueAmt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.TransferredToHoldersAmt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.ReductionApplicationS42Amt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.ReductionApplicationS44Amt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.ReductionApplicationS46Amt.ToString() });
                    newRow.Cells.Add(new System.Web.UI.WebControls.TableCell() { Text = xDataTable.BalanceEndOfYearAmt.ToString() });
                    tblCTC_Data.Rows.Add(newRow);
                }

            }




Tuesday, August 30, 2016

SQL Sample insert sample with declare



Declare @acc1 int
Declare @acc2 int
Select @acc1 = account_id from account where account_number = 'test'
Select @acc2 = account_id from account where account_number = 'test1'



update account_dependency set end_year = 2015
where account_id = @acc1
and dependent_account_id = @acc2
and effective_year = 2012



Insert into account_dependency (account_id, dependent_account_id, curr_year, factor, effective_year, end_year)
values (@acc1, @acc2, 0, 0.800000000, 2016, NULL)

Wednesday, August 10, 2016

Error CS0433 “file' already exists in both xxx.dll and yyy.dll Solution

When this issue is not caused by a bug in the application (e.g., duplicate class name):
This issue appears to present after a change is made to the application's project that results in a new build (e.g., code/reference/resource change). The issue appears to lie within the output of this new build: for various reasons Visual Studio is not replacing the entire contents of your application's obj/bin folders. This results in at least some of the contents of your application's bin folder being out of date.
When said issue occurs, clearing out the "Temporary ASP.NET Files" folder, alone, does not solve the problem. It cannot solve the problem, because the stale contents of your application's bin folder are copied back into the "Temporary ASP.NET Files" folder the next time your application is accessed, causing the issue to persist. The key is to remove all existing files and force Visual Studio to rebuild every object, so the next time your application is accessed the new bin files will be copied into the "Temporary ASP.NET Files" folder.
Solution
  1. Close Visual Studio
  2. Perform an iisreset
  3. Delete all the folders and files within the "Temporary ASP.NET Files" folder (the path is referenced in the error message)
  4. Delete the offending application's "obj" and "bin" folders
  5. Restart Visual Studio and open the solution
  6. Perform a "Clean Solution" followed by a "Rebuild Solution"
Explanation
  • Steps 1-2: remove resource locks from the folders/files we need to delete.
  • Steps 3-4: remove all of the old build files
  • Steps 5-6: create new versions of the build files

Wednesday, July 20, 2016

Finding stored procedure containing specific

SELECT ROUTINE_NAME, ROUTINE_DEFINITION
    FROM INFORMATION_SCHEMA.ROUTINES
    WHERE ROUTINE_DEFINITION LIKE '%Foo%'
    AND ROUTINE_TYPE='PROCEDURE'


SELECT OBJECT_NAME(id)
    FROM SYSCOMMENTS
    WHERE [text] LIKE '%Foo%'
    AND OBJECTPROPERTY(id, 'IsProcedure') = 1
    GROUP BY OBJECT_NAME(id)


SELECT OBJECT_NAME(object_id)
    FROM sys.sql_modules
    WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1
    AND definition LIKE '%Foo%'

Friday, July 15, 2016

create rename do different things with excel workbook


Rename worksheet

You didn't spedify how do you access the excel file. However, example from here might be useful for you if you're using Microsoft.Office.Interop.Excel. Note that it opens first sheet in the file, line: (Worksheet)xlBook.Worksheets.get_Item(1)


using Excel = Microsoft.Office.Interop.Excel;

    object oMissing = System.Reflection.Missing.Value;
    Excel.ApplicationClass xl=new Excel.ApplicationClass();
        Excel.Workbook xlBook;
        Excel.Worksheet xlSheet;
        string laPath = Server.MapPath(@"\excel\xl_table.xls");
        xlBook = (Workbook)xl.Workbooks.Open(laPath,oMissing,
          oMissing,oMissing,oMissing ,oMissing,oMissing,oMissing
         ,oMissing,oMissing,oMissing,oMissing,oMissi ng,oMissing,oMissing);
        xlSheet = (Worksheet)xlBook.Worksheets.get_Item(1);
        xlSheet.Name = "CIAO";
        xlBook.Save();
        xl.Application.Workbooks.Close();


can try below also

 Microsoft.Office.Interop.Excel.Worksheet worksheet = (Worksheet)xlApp.Worksheets["Sheet1"];
  worksheet.Name = “NewTabName”;


Add new worksheet after all worksheets
workbook.Sheets.Add(After: workbook.Sheets[workbook.Sheets.Count]);




Thursday, July 14, 2016

Read all files from directory and delete specific files after sorting

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;


namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string folderPath = @"C:\myfiles\XML";
            List<Int64> fileName = new List<Int64>(); int i = 0;
            foreach (string file in Directory.EnumerateFiles(folderPath, "*.xml"))
            {
                string contents = File.ReadAllText(file);
                fileName.Add(Convert.ToInt64(Path.GetFileNameWithoutExtension(file)));
                Console.WriteLine((fileName[i]).ToString());
                i++;
            }
            Console.WriteLine("sorted order");
            fileName.Sort();
            Console.WriteLine("max value : " + fileName.Max());
            for (int j = 0; j < fileName.Count - 1; j++)
            {
                Console.WriteLine(fileName[j].ToString() + ": will be deleted");
                string file_with_path = folderPath + "\\" + fileName[j].ToString() + ".xml";
                Console.WriteLine(file_with_path + ": will be deleted");
                System.IO.File.Delete(file_with_path);
            }
            Console.ReadLine();
        }
    }
}

Tuesday, July 12, 2016

How many tables in database AdventureWorks have column name like ‘EmployeeID’?

SELECT t.name AS table_name,SCHEMA_NAME(schema_idAS schema_name,c.name AS column_nameFROM sys.tables AS tINNER JOIN sys.columns c ON t.OBJECT_ID c.OBJECT_IDWHERE c.name LIKE '%EmployeeID%'ORDER BY schema_nametable_name;

Thursday, July 7, 2016

How to create Excel file from XML

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Data;
using Excel = Microsoft.Office.Interop.Excel;

namespace xml_to_excel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Excel.Application xlApp;
            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            DataSet ds = new DataSet();
            XmlReader xmlFile;
            int i = 0;
            int j = 0;

            xlApp = new Excel.Application();
            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            xmlFile = XmlReader.Create("product.xml", new XmlReaderSettings());
            ds.ReadXml(xmlFile);
            for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                for (j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
                {
                    for (int k = 0; k < ds.Tables[0].Columns.Count; k++)
                    {
                        xlWorkSheet.Cells[1, k + 1] = ds.Tables[0].Columns[k].ColumnName;
                    }
                    xlWorkSheet.Cells[i + 2, j + 1] = ds.Tables[0].Rows[i].ItemArray[j].ToString();
                }
            }
//make sure the below path exists C:\\access_db\\xml\\
            xlWorkBook.SaveAs("C:\\access_db\\xml\\product2.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();
            releaseObject(xlApp);
            releaseObject(xlWorkBook);
            releaseObject(xlWorkSheet);
            MessageBox.Show("Done .. ");
        }
        private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
            }
            finally
            {
                GC.Collect();
            }
        }
    }
}


create a new xml file in bin folder of the application with name "product.xml" and
add below code

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<Table>
-<Product>
<Product_id>1</Product_id>
<Product_name>Product 1</Product_name>
<Product_price>1000</Product_price>
</Product>
-<Product>
<Product_id>2</Product_id>
<Product_name>Product 2</Product_name>
<Product_price>2000</Product_price>
</Product>
-<Product>
<Product_id>3</Product_id>
<Product_name>Product 3</Product_name>
<Product_price>3000</Product_price>
</Product>
-<Product>
<Product_id>4</Product_id>
<Product_name>Product 4</Product_name>
<Product_price>4000</Product_price>
</Product>
</Table>

Note:  make sure the below path exists  before you execute the appilcation
             C:\\access_db\\xml\\

Monday, June 27, 2016

string formattinf to round off 4 decimal values


double t="o.00005";
  string aa = String.Format("{0:0.#####}", t);

Display 4 decimal place in double.



double a = 23.22;
           string msg = string.Format("E format: {0:N4}", a);
           MessageBox.Show(msg);

Tuesday, June 21, 2016

printing in sql

  Print 'schedule Id value is : ' + convert(varchar(20), @test_id) +    
          ':   @task Id value is : ' + convert(varchar(20), @mycount)

Friday, June 17, 2016

creating Html table dynamically including header in (xhtml)

creating Html table dynamically including header in
(xhtml)

UI

  <asp:TableRow ID="tdrCTC_CTCDetails_GrossIncomeAmt" runat="server" Width="794px">
                    <asp:TableCell Font-Size="XX-Small">
                        <table id="tblCTC_Data" runat="server">
                            <tr id="tdrCTCData_Header">
                                <td runat="server">Description fo Class Shares
                                </td>
                                <td runat="server">(a) Immediately before 1 January 2011
                                </td>
                                <td runat="server">(b) Where the company became a resident since 1 January 2011
                              </td>
                            </tr>
                        </table>
                    </asp:TableCell>
                </asp:TableRow>


aspx page

 tblCTC_Data.Rows.Clear();
            HtmlTableRow headerRow = new HtmlTableRow();
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "Description fo Class Shares" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "(a) Immediately before 1 January 2011" });
            headerRow.Cells.Add(new HtmlTableCell() { InnerText = "(b) Where the company became a resident since 1 January 2011" });

            foreach (HtmlTableCell c in headerRow.Cells)
            {
                c.Style.Add("font-weight", "bold");
            }
 tblCTC_Data.Rows.Add(headerRow);


  if (_rootCustomer.ReturnDetail.CorporateIncomeTaxReturn.CompanyDetails.ContributedTaxCapitalDetails.Count > 0)
            {
//xData of type class //CorporateIncomeTaxReturnStructureCompanyDetailsContributedTaxCapitalDetail //variable
                foreach (CorporateIncomeTaxReturnStructureCompanyDetailsContributedTaxCapitalDetail xDataTable in
                _rootCustomer.ReturnDetail.CorporateIncomeTaxReturn.CompanyDetails.ContributedTaxCapitalDetails)
                {

                    HtmlTableRow newRow = new HtmlTableRow();
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.ShareClassDescription.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.Before1January2011Amt.ToString() });
                    newRow.Cells.Add(new HtmlTableCell() { InnerText = xDataTable.Since1JanuaryAmt.ToString() });
                }

            }



Wednesday, June 1, 2016

Find a specific column entry in an unknown table in a database



DECLARE
   @TotalRows   int,
   @Counter     int,
   @TableName   varchar(50),
   @ColumnName  varchar(50),
   @FieldValue  varchar(250),
   @SQLCommand  nvarchar(1000),
   @ValueToFind varchar(100)


-->
SET @ValueToFind = 'Test case'
-->


DECLARE @MyTable table
   (  RowID      int IDENTITY,
      TableName  varchar(50),
      ColumnName varchar(50)
   )


CREATE TABLE #FoundTable
   (  RowID      int IDENTITY,
      Tablename  varchar(50)
   )



INSERT INTO @MyTable
   SELECT
      TABLE_NAME,
      COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE DATA_TYPE IN ( 'char', 'varchar', 'nchar', 'nvarchar', 'text', 'ntext' )


SELECT
   @TotalRows = @@ROWCOUNT,
   @Counter   = 1


WHILE ( @Counter <= @TotalRows )

 
   BEGIN
  SELECT
         @TableName = TableName,
         @ColumnName = ColumnName
      FROM @MyTable
      WHERE RowID = @Counter

     
      SET @SQLCommand = 'IF EXISTS ( ' +
                        'SELECT 1 FROM [' + @TableName + '] WHERE [' + @ColumnName + '] LIKE ''%' + @ValueToFind + '%'' ' +
                        ' )' +
                        'INSERT INTO #FoundTable ' +
                        '   SELECT ''' + @TableName + '(' + @ColumnName + ')'''
EXECUTE sp_executesql @SQLCommand
     
      SET @Counter = ( @Counter + 1 )

 
   END


SELECT * FROM #FoundTable


DROP TABLE #FoundTable

Delete windows service



sc delete ServiceName

Monday, May 30, 2016

SQL Server Insert if not exist

SQL Server Insert if not exist
BEGIN
   INSERT INTO EmailsRecebidos (De, Assunto, Data)
   VALUES (@_DE, @_ASSUNTO, @_DATA)
   WHERE NOT EXISTS ( SELECT * FROM EmailsRecebidos 
                   WHERE De = @_DE
                   AND Assunto = @_ASSUNTO
                   AND Data = @_DATA);
END
replace with
BEGIN
   IF NOT EXISTS (SELECT * FROM EmailsRecebidos 
                   WHERE De = @_DE
                   AND Assunto = @_ASSUNTO
                   AND Data = @_DATA)
   BEGIN
       INSERT INTO EmailsRecebidos (De, Assunto, Data)
       VALUES (@_DE, @_ASSUNTO, @_DATA)
   END
END

Wednesday, May 25, 2016

installing windows service on server



C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil "sevicepath\service.exe"

Friday, April 29, 2016

Monday, April 25, 2016

exclusive access could not be obtained because the database is in use sql 2008 -------------------- Delete DB ------------ Delete database which is in use -- ( Delete database)

method 1


use master
declare @sql as varchar(20), @spid as int
select @spid = min(spid)  from master..sysprocesses  where dbid = db_id('OneSource2015_DevTest')
and spid != @@spid  

while (@spid is not null)
begin
    print 'Killing process ' + cast(@spid as varchar) + ' ...'
    set @sql = 'kill ' + cast(@spid as varchar)
    exec (@sql)

    select
        @spid = min(spid)
    from
        master..sysprocesses
    where
        dbid = db_id('OneSource2015_DevTest')
        and spid != @@spid
end

print 'Process completed...'


if u want to drop db: use    below line
Drop database OneSource2015_DevTest

method 2:
use master
go
alter database <dbname>
set single_user with rollback immediate
go
alter database <dbname>
set multi_user
go

method 3

alter database database_name
set offline with rollback immediate
go

alter database database_name
set online
go

Thursday, April 21, 2016

list of stored pocs with specific table name







SELECT Name
FROM sys.procedures

WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%table name%'



------Example-------


SELECT Name
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%account_total%'

Friday, April 8, 2016

DB sample

/*
Template for creating a new schedule (Using input fields and linked to accounts)
*/


/* Template for error handling and transactions(big data sets)

declare @newTransactionUId uniqueidentifier
declare @newTransactionId char(36)

set @newTransactionUId = NEWID()
set @newTransactionId = REPLACE(@newTransactionUid,'-','')

select @newTransactionId

begin try
begin transaction @newTransactionId



commit transaction @newTransactionId
end try
begin catch
if(@@TRANCOUNT>0)
begin
rollback transaction @newTransactionId
end
print @@ERROR
end catch

*/

USE OneSource2015
GO

/*

Create table variables.

*/


declare @schedule table
(
client_id int null,
schedule_group_id int null,
schedule_prefix varchar(50) not null,
schedule_name varchar(255) not null,
schedule_sequence int not null,
schedule_type int not null,
schedule_status char(1) not null,
roll_forward bit not null,
effective_year int null,
end_year int null,
modify_date datetime not null,
print_pagesize char(2) null,
print_orientation char(1) null
)

declare @task table
(

[client_id] [int] NULL,
[parent_task] [int] NULL,
[task_description] [varchar](100) NOT NULL,
[task_level] [int] NOT NULL,
[task_sequence] [int] NOT NULL,
[task_type] [char](1) NOT NULL,
[task_url] [varchar](1000) NULL,
[schedule_id] [int] NULL,
[status_ind] [char](1) NOT NULL

)

declare @task_allocation table
(

[task_id] [int] NOT NULL,
[role_id] [uniqueidentifier] NULL,
[client_id] [int] NULL,
[role_ind] [char](1) NULL,
[status_ind] [char](1) NOT NULL,
[modify_date] [datetime] NOT NULL
)

declare  @schedule_parm table
(
[schedule_id] [int] NOT NULL,
[selection] [int] NOT NULL,
[description_id] [int] NOT NULL,
[filter] [varchar](50) NULL,
[linked_schedule_parm_id] [int] NULL,
[linked_filter] [varchar](50) NULL,
[allow_inserts] [bit] NULL
)

declare @schedule_header table
(
      header_text varchar(900) not null
)


declare @schedule_list table
(
    schedule_list_id int not null,
[client_id] [int] NOT NULL,
[list_value] [int] NOT NULL,
[list_text] [varchar](100) NOT NULL,
[status_ind] [char](1) NOT NULL
)


declare @schedule_calculation table
(
         calculation_string  varchar(255) null
)

declare @account table
(
    [client_id] [int] NULL,
[chart_id] [int] NULL,
[account_group] [char](1) NULL,
[account_type_id] [char](1) NULL,
[account_number] [varchar](100) NULL,
[account_description] [varchar](200) NULL,
[effective_year] [int] NOT NULL,
[end_year] [int] NULL,
[status_ind] [char](1) NOT NULL,
[modify_date] [datetime] NOT NULL
)

declare @schedule_template table
(
[schedule_id] [int] NOT NULL,
[column_no] [int] NOT NULL,
[client_id] [int] NOT NULL,
[selection] [int] NOT NULL,
[schedule_header_id] [int] NULL,
[schedule_list_id] [int] NULL,
[account_id] [int] NULL,
[calculation_id] [int] NULL,
[column_type] [char](1) NOT NULL,
[column_format] [varchar](50) NULL,
[protected_ind] [bit] NOT NULL,
[display_ind] [bit] NOT NULL,
[display_sequence] [int] NOT NULL,
[print_ind] [bit] NOT NULL,
[print_sequence] [int] NULL,
[sort_sequence] [int] NULL,
[sort_asc] [bit] NULL,
[filter] [varchar](255) NULL,
[effective_year] [int] NOT NULL,
[rollover_column] [int] NULL,
[end_year] [int] NULL,
[modify_date] [datetime] NOT NULL,
[group_by] [int] NOT NULL,
[linked_column] [int] NULL

)


declare @schedule_footer table
(
[client_id] [int] NOT NULL,
[schedule_id] [int] NOT NULL,
[selection] [int] NOT NULL,
[line_no] [int] NOT NULL,
[column_no] [int] NOT NULL,
[schedule_header_id] [int] NULL,
[account_id] [int] NULL,
[calculation_id] [int] NULL,
[column_type] [char](1) NOT NULL,
[column_format] [varchar](50) NULL,
[column_style] [varchar](50) NULL,
[reverse_account] [int] NULL,
[balance_account_id] [int] NULL,
[effective_year] [int] NOT NULL,
[end_year] [int] NULL
)


declare @schedule_list_id int
set @schedule_list_id =
(
      select
            MAX(schedule_list_id) +1
      from schedule_list
)


declare @newTransactionUId uniqueidentifier
declare @newTransactionId char(36)


set @newTransactionUId = NEWID()
set @newTransactionId = REPLACE(@newTransactionUid,'-','')



begin try
begin transaction @newTransactionId

  -- 1.) Insert into schedule temp table:

          insert into @schedule
select
null 'client_id',
(
select top 1
schedule_group_id
from
schedule_group
where
group_name='K - Section 6quat rebate'
)  'schedule_group_id',
'C 4.5' 'schedule_prefix',
'Transfer pricing and financial' 'schedule_name',
18 'schedule_sequence',
1 'schedule_type',
'S' 'schedule_status',
0 'roll_forward',
2006 'effective_year',
null 'end_year',
GETDATE() 'modify_date',
'A4' 'print_pagesize',
'P' 'print_orientation'


SELECT 'schedule' As title
select * from @schedule AS schedule



  -----Actual insert from temp table to actual table

insert
into schedule
(client_id,schedule_group_id,schedule_prefix,schedule_name,schedule_sequence,schedule_type,schedule_status,roll_forward,effective_year,end_year,modify_date,print_pagesize,print_orientation)
SELECT
new.client_id,
new.schedule_group_id,
new.schedule_prefix 'schedule_prefix',
new.schedule_name 'schedule_name',
new.schedule_sequence,
new.schedule_type,
new.schedule_status,
new.roll_forward,
new.effective_year,
new.end_year,
new.modify_date,
new.print_pagesize,
new.print_orientation
FROM
schedule existing
right join
@schedule new
on
(
new.schedule_prefix=existing.schedule_prefix and
new.schedule_name=existing.schedule_name
)
where
existing.schedule_prefix is null
and
existing.schedule_name is null

select * from schedule


-- 2. insert into schedule_parm temp table

insert into @schedule_parm
select
ISNULL((
select
top 1 schedule_id
from
schedule
where
schedule_prefix='C 4.5'
and
schedule_name ='Transfer pricing and financial'
),0) 'schedule_id',
0 'selection',
ISNULL((
select
top 1 schedule_id
from
schedule
where
schedule_prefix='C 4.5'
and
schedule_name ='Transfer pricing and financial'
),0) 'description_id',
null 'filter',
null 'linked_schedule_parm_id',
null 'linked_filter',
null 'allow_inserts'


---Actual insert into schedule_param table
INSERT INTO
schedule_parm(schedule_id,selection,description_id,filter,linked_schedule_parm_id,linked_filter,allow_inserts)
SELECT
new.schedule_id 'schedule_id',
new.selection,
new.description_id 'description_id',
new.filter,
new.linked_schedule_parm_id,
new.linked_filter,
new.allow_inserts
FROM  
schedule_parm existing
right join
@schedule_parm new
on
(
new.schedule_id=existing.schedule_id and
new.description_id=existing.description_id
)
where
existing.schedule_id is null and
existing.description_id is null



SELECT 'schedule_parm' As title
    select * from @schedule_parm AS schedule_parm
    select * from schedule_parm AS schedule_parm
 
 
 
   --3. insert into task temp table
insert into @task
select
null 'client_id',
(
select
 parent_task
from task where task_id=171
)
'parent_task',
 'Schedule C 4.5 - Transfer pricing and financial' 'task_description',
 5 'task_level',
 41 'task_sequence',
 'P' 'task_type',
 ISNULL((select
'frmDisclosureScheduleEngine.aspx?Schedule_Parm_ID=' +
CONVERT(NVARCHAR(50),(select
schedule_parm_id
from
schedule_parm
where
schedule_id =
ISNULL((
select
top 1 schedule_id
from
schedule
where
schedule_prefix='C 4.5'
and
schedule_name ='Transfer pricing and financial'
),0)))
),0) 'task_url',
ISNULL((
select
top 1 schedule_id
from
schedule
where
schedule_prefix='C 4.5'
and
schedule_name ='Transfer pricing and financial'
),0) 'schedule_id',
'A' 'status_ind'



---Actual insert into Task table

INSERT
INTO
Task(client_id,parent_task,task_description,task_level,task_sequence,task_type,task_url,schedule_id,status_ind)
SELECT
new.client_id,
new.parent_task,
new.task_description 'task_description',
new.task_level,
new.task_sequence,
new.task_type,
new.task_url  'task_url',
new.schedule_id 'schedule_id',
new.status_ind
FROM
task  existing
right join
@task new
on
(
existing.task_description=new.task_description and
existing.task_url=new.task_url
)
where
existing.task_description is null and
existing.task_url is null

SELECT 'Tasktable' As title
select * from @task   as   Task
select * from task


--4.  insert into temp task_allocation table

insert into @task_allocation
                  select    
                              ISNull((select
                                                top 1 task_id
                                          from
                                    task
                              where
                                    task_description='Schedule C 4.5 - Transfer pricing and financial')
                                    ,0)
                'task_id',
                (
                        select
                              top 1 roleid
                        from
                              aspnet_Roles
                        where
                              RoleName = 'Admin'
                ) 'role_id',
                null 'client_id',
                'S'  'role_ind',
                'A' 'status_ind',
                getdate() 'modify_date'
               
            insert into @task_allocation
                  select    
                              ISNull((select
                                                top 1 task_id
                                          from
                                    task
                              where
                                    task_description='Schedule C 4.5 - Transfer pricing and financial')
                                    ,0)
                'task_id',
                (
                        select
                              top 1 roleid
                        from
                              aspnet_Roles
                        where
                              RoleName = 'SuperUser'
                ) 'role_id',
                null 'client_id',
                'S'  'role_ind',
                'A' 'status_ind',
                getdate() 'modify_date'
               
            insert into @task_allocation
                  select    
                              ISNull((select
                                                top 1 task_id
                                          from
                                    task
                              where
                                    task_description='Schedule C 4.5 - Transfer pricing and financial')
                                    ,0)
                'task_id',
                (
                        select
                              top 1 roleid
                        from
                              aspnet_Roles
                        where
                              RoleName = 'Reviewer'
                ) 'role_id',
                null 'client_id',
                'S'  'role_ind',
                'A' 'status_ind',
                getdate() 'modify_date'
               
            insert into @task_allocation
                  select    
                              ISNull((select
                                                top 1 task_id
                                          from
                                    task
                              where
                                    task_description='Schedule C 4.5 - Transfer pricing and financial')
                                    ,0)
                'task_id',
                (
                        select
                              top 1 roleid
                        from
                              aspnet_Roles
                        where
                              RoleName = 'Preparer'
                ) 'role_id',
                null 'client_id',
                'S'  'role_ind',
                'A' 'status_ind',
                getdate() 'modify_date'

 
  -----actual insert into TaskAllocation table

INSERT
                  INTO
                        task_allocation(task_id,role_id,status_ind,modify_date)
            select
                        new.task_id 'task_id',
                        new.role_id,
                        new.status_ind,
                        new.modify_date
            from
                        task_allocation existing
                        right join
                        @task_allocation new
                        on
                              (                            
                        existing.task_id=new.task_id and
                        existing.role_id=new.role_id
                              )
            where
                              existing.task_id is null


SELECT 'taskallocationtable' As title  
select * from @task_allocation  as taskallocationtable
select * from task_allocation  as taskallocationtable


--5.  insert into temp  schedule_header table
insert into @schedule_header
select
'Nature' 'header_text'
union
select
'Amount' 'header_text'
union
select
'Transfer pricing adjustment' 'header_text'
union
select
'Financial assistance' 'header_text'
union
select
'Transfer pricing other than financial assistance' 'header_text'


----actual insert into ScheduleHeader  Table
INSERT INTO schedule_header(header_text)
select
new.header_text 'header_text'
from
schedule_header existing
right join
@schedule_header new
on
(
existing.header_text=new.header_text
)
where
existing.header_text is null


SELECT 'ScheduleHeaderTable' As title  
select * from @schedule_header  as ScheduleHeaderTable



--6.  insert into temp Schedule_list  table
   insert into @schedule_list
      select  
            @schedule_list_id 'schedule_list_id',
            0 'client_id',
            1 'list_value',
            'Yes' 'list_text',
            'A' 'status_ind'          
            union
            select
            @schedule_list_id 'schedule_list_id',
            0 'client_id',
            2 'list_value',
            'No' 'list_text',
            'A' 'status_ind'



--- actual insert into schedule_list  table
insert into schedule_list
(client_id,list_value,list_text,status_ind)
select
new.client_id,
new.list_value,
new.list_text,
new.status_ind
from
schedule_list  existing
right join
@schedule_list new
on
(
  existing.schedule_list_id=new.schedule_list_id and
  existing.list_value=new.list_value
)
where
existing.list_value is null

SELECT 'schedule_listTable' As title  
select * from @schedule_list as schedule_listTable


--7.  insert into temp account table
insert into @account
select
 null 'client_id',
 1 'chart_id',
 'S' 'account_group',
 null 'account_type_id',
 'C 4.5' 'account_number',
 'Transfer pricing and financial' 'account_description',
 2007 'effective_year',
 null 'end_year',
 'A' 'status_ind',
 GETDATE() 'modify_date'


 ---insert into actual table
 insert
into
account(client_id,chart_id,account_group,account_type_id,account_number,account_description,effective_year,end_year,status_ind,modify_date)
 select
new.client_id,
new.chart_id,
new.account_group,
new.account_type_id,
new.account_number,
new.account_description,
new.effective_year,
new.end_year,
new.status_ind,
new.modify_date
from
account existing
right join
   @account new
on
(
existing.account_number=new.account_number and
existing.account_description=new.account_description
)
where
existing.account_number is null and
existing.account_description is null



SELECT 'accountTable' As title  
select * from @account  as accountTable


--8.  insert into temp schedule_template table
insert into @schedule_template
select
ISNULL(
      (select
            top 1
           schedule_id
            from schedule where
            schedule_prefix = 'C 4.5' and
       schedule_name='Transfer pricing and financial' )
     ,0) 'schedule_id',
   
      1 'column_no',
      0 'client_id',
      0 'selection',
      ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Nature'
),0) 'schedule_header_id',

null 'schedule_list_id',
null 'account_id',
null 'calculation_id',
'M' 'column_type',
null 'column_format',
0 'protected_ind',
1 'display_ind',
1 'display_sequence',
1 'print_ind',
1 'print_sequence',
null 'sort_sequence',
null 'sort_asc',
null 'filter',
   2006 'effective_year',
null 'rollover_column',
null 'end_year',
getdate() 'modify_date',
0 'group_by',
null 'linked_column'

---union 'Amount'
union

select
           ISNULL(
  (select
top 1
schedule_id
        from schedule where
        schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
 ,0) 'schedule_id',
   
  2 'column_no',
  0 'client_id',
  0 'selection',
  ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Amount'
),0) 'schedule_header_id',

null 'schedule_list_id',
ISNULL (
(
select top 1 account_id
    from account
where
   account_description='Transfer pricing and financial')
,0) 'account_id',
null 'calculation_id',
'M' 'column_type',
'{0:#,#.00}' 'column_format',
0 'protected_ind',
1 'display_ind',
2 'display_sequence',
1 'print_ind',
2 'print_sequence',
null 'sort_sequence',
null 'sort_asc',
null 'filter',
2006 'effective_year',
null 'rollover_column',
null 'end_year',
getdate() 'modify_date',
0 'group_by',
null 'linked_column'
--union 'Transfer pricing adjustment'
union

select
           ISNULL(
  (select
top 1
schedule_id
        from schedule where
        schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
 ,0) 'schedule_id',
   
  3 'column_no',
  0 'client_id',
  0 'selection',
  ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Transfer pricing adjustment'
),0) 'schedule_header_id',

189 'schedule_list_id',
null 'account_id',
null 'calculation_id',
'M' 'column_type',
null 'column_format',
0 'protected_ind',
1 'display_ind',
3 'display_sequence',
1 'print_ind',
3 'print_sequence',
null 'sort_sequence',
null 'sort_asc',
null 'filter',
2006 'effective_year',
null 'rollover_column',
null 'end_year',
getdate() 'modify_date',
0 'group_by',
null 'linked_column'


union

select
ISNULL(
  (select
top 1
schedule_id
        from schedule where
        schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
 ,0) 'schedule_id',
   
  4 'column_no',
  0 'client_id',
  0 'selection',
  ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Financial assistance'
),0) 'schedule_header_id',

null 'schedule_list_id',
null 'account_id',
null 'calculation_id',
'M' 'column_type',
'{0:#,#.00}' 'column_format',
0 'protected_ind',
1 'display_ind',
4 'display_sequence',
1 'print_ind',
4 'print_sequence',
null 'sort_sequence',
null 'sort_asc',
null 'filter',
2006 'effective_year',
null 'rollover_column',
null 'end_year',
getdate() 'modify_date',
0 'group_by',
null 'linked_column'

      -----union Transfer pricing other than financial assistance
      ---no account id,no List id,follow column format
      union
      select
ISNULL(
  (select
top 1
schedule_id
        from schedule where
        schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
 ,0) 'schedule_id',
   
  4 'column_no',
  0 'client_id',
  0 'selection',
  ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Transfer pricing other than financial assistance'
),0) 'schedule_header_id',

null 'schedule_list_id',
null 'account_id',
null 'calculation_id',
'M' 'column_type',
'{0:#,#.00}' 'column_format',
0 'protected_ind',
1 'display_ind',
5 'display_sequence',
1 'print_ind',
5 'print_sequence',
null 'sort_sequence',
null 'sort_asc',
null 'filter',
2006 'effective_year',
null 'rollover_column',
null 'end_year',
getdate() 'modify_date',
0 'group_by',
null 'linked_column'
   
     SELECT 'schedule_templateTable' As title  
    select * from @schedule_template as schedule_templateTable
   
   
   
    --9.  insert into temp schedule_footer table
   
    ---------insert options for Column_no,scheduleheader_id,account_id,column_type,column_format,column_style,reverse_account,balance_account_id
    /*  Case 1
    headertext=Nature
    Column_no 4,
    scheduleheader_id null,
    account_id get acc id,
    column_type M,
    column_format FORMAT,
    column_style  NULL,
    reverse_account 0,
    balance_account_id NULL
    */
    insert into @schedule_footer  
   
   
     /*  case 1
    headertext=Nature
    Column_no 1,
    scheduleheader_id GET ID,
    account_id get acc NULL,
    column_type T,
    column_format null,
    column_style  'font-weight:bold',
    reverse_account 0,
    balance_account_id NULL
    */
    select
     0 'client_id',
           ISNULL(
      (select
            top 1
           schedule_id
            from schedule where
            schedule_prefix = 'C 4.5' and
       schedule_name='Transfer pricing and financial' )
     ,0) 'schedule_id'      
           ,0 'selection'
           ,1 'line_no'
           ,4 'column_no'
           ,null 'schedule_header_id'
           ,ISNULL (
(
select top 1 account_id
    from account
where
   account_description='Transfer pricing and financial')
,0)  'account_id'
           ,null 'calculation_id'
           ,'M' 'column_type'
           ,'{0:#,#.00}' 'column_format'
           ,null 'column_style'
           ,0 'reverse_account' --------TBA
           ,null 'balance_account_id'       ---------TBA
           ,2006 'effective_year'          
           ,0  'end_year'
         
                   
           union
         
         
         
            /*  case 2
    headertext=Nature
    Column_no 1,
    scheduleheader_id GET ID,
    account_id get acc NULL,
    column_type T,
    column_format null,
    column_style  'font-weight:bold',
    reverse_account 0,
    balance_account_id NULL
    */
select
0 'client_id',
ISNULL(
(select
top 1
schedule_id
from schedule where
schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
,0) 'schedule_id'      
,0 'selection'
,1 'line_no'
,1 'column_no'
, ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Nature'
),0) 'schedule_header_id'
,null  'account_id'
,null 'calculation_id'
,'T' 'column_type'
,null 'column_format'
,'font-weight:bold' 'column_style'
,0 'reverse_account' --------TBA
,null 'balance_account_id'       ---------TBA
,2006 'effective_year'          
,0  'end_year' --------TBA    

        union    
         
         
            /*  case 3
    headertext=Amount
    line number=2
    Column_no 1,
    scheduleheader_id GET ID,
    account_id get acc NULL,
    column_type T,
    column_format null,
    column_style  'font-weight:bold',
    reverse_account 0,
    balance_account_id NULL
    */

select
0 'client_id',
ISNULL(
(select
top 1
schedule_id
from schedule where
schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
,0) 'schedule_id'      
,0 'selection'
,2 'line_no'
,1 'column_no'
, ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Amount'
),0) 'schedule_header_id'
,null  'account_id'
,null 'calculation_id'
,'T' 'column_type'
,null 'column_format'
,'font-weight:bold' 'column_style'
,0 'reverse_account' --------TBA
,null 'balance_account_id'       ---------TBA
,2006 'effective_year'          
,0  'end_year' --------TBA  

union


 /*  case 4
    headertext=Amount
    line number=2
    Column_no 4,
    scheduleheader_id GET ID,
    account_id get acc getaid,
    column_type m,
    column_format null,
    column_style  bold,
    reverse_account tba null,
    balance_account_id NULL
    */

select
0 'client_id',
ISNULL(
(select
top 1 schedule_id
from
schedule
where
schedule_prefix = 'C 4.5'
and
schedule_name='Transfer pricing and financial' )
,0) 'schedule_id'      
,0 'selection'
,2 'line_no'
,4 'column_no'
, ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Amount'
),0)
'schedule_header_id'
,ISNULL (
(select
top 1 account_id
from
account
where
account_description='Transfer pricing and financial')
,0)
'account_id'
,null 'calculation_id'
,'M' 'column_type'
,'{0:#,#.00}' 'column_format'
,null 'column_style'
,0 'reverse_account' --------TBA
,null 'balance_account_id'       ---------TBA
,2006 'effective_year'          
,0  'end_year' --------TBA  

union

 /*  case 5
    headertext='Transfer pricing adjustment'
    line number=3  
    Column_no 4,
    scheduleheader_id GET ID,
    account_id get acc getaid,
    column_type m,
    column_format null,
    column_style  bold,
    reverse_account tba null,
    balance_account_id NULL
    */

select
0 'client_id',
ISNULL(
(select
top 1
schedule_id
from schedule where
schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
,0) 'schedule_id'      
,0 'selection'
,2 'line_no'
,1 'column_no'
, ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Transfer pricing adjustment'
),0) 'schedule_header_id'
,ISNULL (
(
select top 1 account_id
from
account
where
account_description='Transfer pricing and financial')
,0)
'account_id'
,null 'calculation_id'
,'M' 'column_type'
,'{0:#,#.00}' 'column_format'
,null 'column_style'
,0 'reverse_account' --------TBA
,null 'balance_account_id'       ---------TBA
,2006 'effective_year'          
,0  'end_year' --------TBA  


union


 /*  case 6
    headertext='Transfer pricing adjustment'
    line number=3  
    Column_no 1,
    scheduleheader_id GET ID,
    account_id  null,
    column_type T,
    column_format null,
    column_style  bold,
    reverse_account tba null,
    balance_account_id NULL
    */

select
0 'client_id',
ISNULL(
(select
top 1
schedule_id
from schedule where
schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
,0) 'schedule_id'      
,0 'selection'
,2 'line_no'
,1 'column_no'
, ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Transfer pricing adjustment'
),0) 'schedule_header_id'
,null  'account_id'
,null 'calculation_id'
,'M' 'column_type'
,null 'column_format'
,'font-weight:bold' 'column_style'
,0 'reverse_account' --------TBA
,null 'balance_account_id'       ---------TBA
,2006 'effective_year'          
,0  'end_year' --------TBA  


union


 /*  case 7
    headertext='Financial assistance'
    line number=4  
    Column_no 1,
    scheduleheader_id GET ID,
    account_id  null,
    column_type T,
    column_format null,
    column_style  bold,
    reverse_account tba null,
    balance_account_id NULL
    */

select
0 'client_id',
ISNULL(
(select
top 1
schedule_id
from schedule where
schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
,0) 'schedule_id'      
,0 'selection'
,4 'line_no'
,1 'column_no'
, ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Financial assistance'
),0) 'schedule_header_id'
,null 'account_id'
,null 'calculation_id'
,'M' 'column_type'
,null 'column_format'
,'font-weight:bold' 'column_style'
,0 'reverse_account' --------TBA
,null 'balance_account_id'       ---------TBA
,2006 'effective_year'          
,0  'end_year' --------TBA


        union
       
       
          /*  case 8
    headertext='Financial assistance'
    line number=4  
    Column_no 4,
    scheduleheader_id GET ID,
    account_id  getId,
    column_type M,
    column_format '{0:#,#.00}',
    column_style  null,
    reverse_account tba null,
    balance_account_id NULL
    */

select
0 'client_id',
ISNULL(
(select
top 1
schedule_id
from schedule where
schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
,0) 'schedule_id'      
,0 'selection'
,4 'line_no'
,1 'column_no'
, ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Financial assistance'
),0)
'schedule_header_id'
,ISNULL (
(select
top 1 account_id
from
account
   where
account_description='Transfer pricing and financial')
,0)
'account_id'
,null 'calculation_id'
,'M' 'column_type'
,'{0:#,#.00}' 'column_format'
,null 'column_style'
,0 'reverse_account' --------TBA
,null 'balance_account_id'       ---------TBA
,2006 'effective_year'          
,0  'end_year' --------TBA
       
        union
       
       
       
       
            /*  case 9
    headertext='Transfer pricing other than financial assistance'
    line number=5  
    Column_no 4,
    scheduleheader_id GET ID,
    account_id  getId,
    column_type M,
    column_format '{0:#,#.00}',
    column_style  null,
    reverse_account tba null,
    balance_account_id NULL
    */

select
0 'client_id',
ISNULL(
(select
top 1
schedule_id
from schedule where
schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
,0) 'schedule_id'      
,0 'selection'
,5 'line_no'
,4 'column_no'
, ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Transfer pricing other than financial assistance'
),0)
'schedule_header_id'
,ISNULL (
(select
top 1 account_id
from
account
   where
account_description='Transfer pricing and financial')
,0)
'account_id'
,null 'calculation_id'
,'M' 'column_type'
,'{0:#,#.00}' 'column_format'
,null 'column_style'
,0 'reverse_account' --------TBA
,null 'balance_account_id'       ---------TBA
,2006 'effective_year'          
,0  'end_year' --------TBA
       
        union
       
                  /*  case 10
    headertext='Transfer pricing other than financial assistance'
    line number=5  
    Column_no 1,
    scheduleheader_id GET ID,
    account_id  null,
    column_type t,
    column_format null,
    column_style  bold,
    reverse_account tba null,
    balance_account_id NULL
    */

select
0 'client_id',
ISNULL(
(select
top 1
schedule_id
from schedule where
schedule_prefix = 'C 4.5' and
schedule_name='Transfer pricing and financial' )
,0) 'schedule_id'      
,0 'selection'
,5 'line_no'
,1 'column_no'
, ISNULL((
select
top 1 schedule_header_id
from
schedule_header
where
header_text = 'Transfer pricing other than financial assistance'
),0)
'schedule_header_id'
,null 'account_id'
,null 'calculation_id'
,'T' 'column_type'
,null 'column_format'
,'font-weight:bold' 'column_style'
,0 'reverse_account' --------TBA
,null 'balance_account_id'       ---------TBA
,2006 'effective_year'          
,0  'end_year' --------TBA
       
         
     SELECT 'schedule_footerTable' As title  
    select * from  @schedule_footer  AS  schedule_footerTable
   



commit transaction @newTransactionId
end try
begin catch
if(@@TRANCOUNT>0)
begin
rollback transaction @newTransactionId
end
SELECT
        ERROR_NUMBER() AS ErrorNumber,
        ERROR_MESSAGE() AS ErrorMessage;
end catch








 
 
 









commit transaction @newTransactionId
end try
begin catch
if(@@TRANCOUNT>0)
begin
rollback transaction @newTransactionId
end
SELECT
        ERROR_NUMBER() AS ErrorNumber,
        ERROR_MESSAGE() AS ErrorMessage;
end catch