Skip to main content

Posts

SQL NEW INSERT STORE PROCEDURE DYNAMICALLY

IF EXISTS (         SELECT *         FROM dbo.sysobjects         WHERE id = object_id(N'[dbo].[test_create_procedure]')             AND OBJECTPROPERTY(id, N'IsProcedure') = 1         )     DROP PROCEDURE [dbo].[test_create_procedure] GO SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS OFF GO ALTER PROCEDURE create_procedure @table VARCHAR(200),     @DeveloperName VARCHAR(200),     @Createtable VARCHAR(20)     --create_procedure 'Products','VISHAL','Products' AS SET NOCOUNT ON DECLARE @testTable VARCHAR(8000) DECLARE @testTable2 VARCHAR(8000) DECLARE @testTable3 VARCHAR(8000) DECLARE @opration VARCHAR(8000) DECLARE @testTable_UPDATE VARCHAR(8000) DECLARE @final VARCHAR(8000) DECLARE @OP VARCHAR(100) SET @testTable = '' SET @testTable2 = '' SET @final = '' SET @testTable3 =...

DYNAMIC SQL INSERT STATEMENT

create table #tmp ( SQLText varchar(8000) ) create table #tmp2 ( Id int identity, SQLText varchar(8000) ) set nocount on delete #tmp delete #tmp2 declare @vsSQL varchar(8000), @vsCols varchar(8000), @vsTableName varchar(40) declare csrTables cursor for select name from sysobjects where type in ('u') and name in ('Customers') order by name open csrTables fetch next from csrTables into @vsTableName while (@@fetch_status = 0) begin select @vsSQL = '', @vsCols = '' select @vsSQL = @vsSQL + CASE when sc.type in (39,47,61,111) then '''''''''+' + 'isnull(rtrim(replace('+ sc.name + ','''''''','''''''''''')),'''')' + '+'''''',''+' when sc.type = 35 then '''''''''+...

datatable group by

private DataTable GetGroupedBy(DataTable dt, string columnNamesInDt, string groupByColumnNames, string typeOfCalculation) { //Return its own if the column names are empty if (columnNamesInDt == string.Empty || groupByColumnNames == string.Empty) { return dt; } //Once the columns are added find the distinct rows and group it bu the numbet DataTable _dt = dt.DefaultView.ToTable(true, groupByColumnNames); //The column names in data table string[] _columnNamesInDt = columnNamesInDt.Split(','); for (int i = 0; i < _columnNamesInDt.Length; i = i + 1) { if (_columnNamesInDt[i] != groupByColumnNames) { _dt.Columns.Add(_columnNamesInDt[i]); } } //Gets the collection and send it back for (int i = 0; i < _dt.Rows.Count; i = i + 1) { for (int j = 0; j < _columnNamesInDt.Length; j = j + 1) { if (_columnNamesInDt[j] != groupByColumnNames) { _dt.Rows[i][j] = dt.Compute(typeOfCalculation + "(" + _columnNamesInDt[j] + ")", groupByColumnName...

Building a Database Driven Hierarchical Menu using ASP.NET

Download AspSooperFish

ASP.NET DATE FORMAT CUSTOME

string SSS = DateTime.Now.ToString("dddd, d MMMM, yyyy", CultureInfo.CreateSpecificCulture("en-US")); DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15); Console.WriteLine(date1.ToString( "ddd d MMM" , CultureInfo.CreateSpecificCulture( "en-US" ))); // Displays Fri 29 Aug Console.WriteLine(date1.ToString( "ddd d MMM" , CultureInfo.CreateSpecificCulture( "fr-FR" ))); // Displays ven. 29 août      DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15, 18); CultureInfo ci = CultureInfo.InvariantCulture; Console.WriteLine(date1.ToString( "hh:mm:ss.f" , ci)); // Displays 07:27:15.0 Console.WriteLine(date1.ToString( "hh:mm:ss.F" , ci)); // Displays 07:27:15 Console.WriteLine(date1.ToString( "hh:mm:ss.ff" , ci)); // Displays 07:27:15.01 Console.WriteLine(date1.ToString( "hh:mm:ss.FF" , ci)); // Displays 07:27:15.01 Console.WriteLine(date1....

SQL PARENT CHILD TREE STRUCTURE

-- DECLARE DECLARE @Company AS TABLE(EmpID INT, ParentID INT, PersonName VARCHAR(100)); -- Insert Temp Records INSERT INTO @Company(EmpID, ParentID, PersonName) VALUES(1 , NULL , 'Maulik Dhorajia')     , (2 , NULL , 'Bhavesh Gohel')     , (3 , NULL , 'Dinesh Padhiyar')     , (4 , 2 , 'Vijay Kumar')     , (5 , 1 , 'Jitendra Makwana')     , (6 , 4 , 'Jayesh Dhobi')     , (7 , 1 , 'Shivpalsinh Jhala')     , (8 , 5 , 'Amit Patel')     , (9 , 3 , 'Abidali Suthar') -- Default data SELECT * FROM @Company; -- Incorrect result which we usually find on Internet ;WITH CTECompany AS (     SELECT EmpID, ParentID, PersonName , 0 AS HLevel     FROM @Company     WHERE ParentID IS NULL         UNION ALL         SELECT C.EmpID, C.ParentID, C.PersonName , (CTE.HLevel + 1) AS HLevel ...

Creating Mailing Labels in SQL Server Reporting Services

Most word processing applications (Word, WordPerfect, and so on) provide the capability to create a “mail merge” from which to generate mailing labels in different formats and layouts. Mailing labels are an automated way to generate the address labels for a large number of envelopes or parcels that need to be mailed. Reporting Services provides a few features that allow you to create mailing labels in different formats - the only thing you need to know are the exact dimensions of the label template you are targeting when printing. A common mailing label format is to use multiple columns (newspaper layout) in order to maximize the number of labels printed. This recipe shows you how to leverage Reporting Services’ multi-column layout features to create basic mailing labels, while explaining certain limitations in the rendering engine. Product Versions All versions (examples provided in Reporting Services 2008) What You’ll Need AdventureWorksDW2008...