Posts

Showing posts with the label Functions

How to select data from another sql server

We have a target to run a JOB on server to import data from another SQL server instance. For example take Server 1 - Main Server 2 - From which we have to import. If you have admin rights on both the servers you can "Link the servers" under "Server Objects>>Linked Servers" Right click on the same and provide all the parameters of server or as an alternate you can run following command. EXEC sp_addlinkedserver @server = 'db1', @srvproduct = 'SQLServer OLEDB Provider',  @provider = 'SQLOLEDB',  @datasrc = 'server2',  @provstr='User Id=sa; Password=abc' The above command parameters:-  @server- An identification name of server. @datasrc- Your server instance name or IP. Your SQL will look like:- Select * from db1.dbname.dbo.tablename If sometimes the server will get changed, the above statement gives you the option to change the user name, password and server at any points of time without effecting the ...

How to pass server values to Javascript using Eval()

In my application I have a target to show message if user does not have permission to navigate to another page. I can do this by using server code but it will make a round trip to server and make a bad user experience so, I decided to use java script. Following is the function of Java Script <script language="javascript" type="text/javascript"> function func_Message(obj) { if (parseFloat(obj)>0) { return true; } else { alert("Please assign a value before viewing the details"); return false; } } </script> And following is the code of Link Button from where I am passing value to Java Script Function <asp:LinkButton ID="lnk_Details" runat="server" Text="Details" CommandArgument='<%# Eval("festi_id") +"~" + Eval("user_id") %>' CommandName="ViewDet...

How to alter Auto Increment field in Sql server

It is not possible to remove Auto Increment field using Alter command in Sql Server. What we can use is SET IDENTITY_INSERT Take this following example this creates a table with auto increment field and still insert data to the same. Generally if you try to insert the data into auto increment field it will through error. But if we use SET IDENTITY_INSERT <Table Name>ON it will allow you to insert data into auto increment field. Note: Make sure after completing this operation you set the value to SET IDENTITY_INSERT <Table Name>OFF --Create table and its columns CREATE TABLE [test].[Table_1] ( [Id][int] NOT NULL IDENTITY (1, 1), [Name][nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL); GO ALTER TABLE [test].[Table_1] ADD CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED ([Id]) GO SET IDENTITY_INSERT [test].[Table_1] ON GO INSERT INTO [test].[Table_1] ([Id], [Name]) VALUES (1, 'Narender') GO INSERT INTO [test].[Table_1] ([Id], [Name]) VALUES (3, ...

SQL Function Reference:Oracle vs.SQL Server vs. My SQL Part- III

Date Functions Function - Date addition Oracle - (use +) SQL Server - DATEADD My Sql - Need To Update Function - Date subtraction Oracle - (use -) SQL Server - DATEDIFF My Sql - Need To Update Function - Last day of month Oracle - LAST_DAY SQL Server - N/A My Sql - Need To Update Function -Time zone conversion Oracle - NEW_TIME SQL Server - N/A My Sql - Need To Update Function -First weekday after date Oracle - NEXT_DAY SQL Server - N/A My Sql - Need To Update Function -Convert date to string Oracle -TO_CHAR SQL Server - DATENAME My Sql - Need To Update Function -Convert date to number Oracle -TO_NUMBER(TO_CHAR()) ...

SQL Function Reference:Oracle vs.SQL Server vs. My SQL Part- II

String Functions Function - Convert character to ASCII Oracle - ASCII SQL Server - ASCII My Sql - ASCII Function -String concatenate Oracle - CONCAT SQL Server - (expression + expression) My Sql - CONCAT Function -Convert ASCII to character Oracle - CHR SQL Server - CHAR My Sql - CONCAT Function -Return starting point of character in character string (from left) Oracle - INSTR SQL Server - CHARINDEX My Sql - INSTR Function -Convert characters to lowercase Oracle - LOWER SQL Server - LOWER My Sql - LOWER Function -Convert characters to uppercase Oracle - UPPER SQL Server - UPPER My Sql - UPPER Function -Pad left side of character string Oracle - LPAD SQL Server - N/A My Sql - LPAD Function -Remove leading blank spaces Oracle - LTRIM SQL Server - LTRIM My Sql - LTRIM Function -Remove trailing bl...

SQL Function Reference:Oracle vs.SQL Server vs. My SQL Part- I

Generally the major issue we face while development is the availability of common functions in different database(s). I am facing this issue from last so many years. Then I had start preparing a table for common functions of different database(s). The commonly used databases are Oracle, Sql Server and My Sql. Their is so many other database(s) are also available but commonly I works on these database(s) only. Following is the common list of functions in different database(s):- Math Functions Function - Absolute value Oracle - ABS SQL Server - ABS My Sql - ABS Function - Arc cosine Oracle - ACOS SQL Server - ACOS My Sql - ACOS Function - Arc sine Oracle - ASIN SQL Server - ASIN My Sql - ASIN Function - Arc tangent of n Oracle - ATAN SQL Server - ATAN My Sql - ATAN Function - Arc tangent of n and m Oracle - ATAN2 SQL Server - ATAN2 My Sql - Please Suggest Function - Smallest integer >= value Orac...

How to get tables names in MySql (sysobjects in sql server)

In Sql server we have a table sysobjects which holds names of all the tables i.e. system and user tables. Like the same we have command “Show tables” which show all the tables of specified database. Syntax Show Tables from <databasename> Here is an example. SHOW TABLES FROM MySql If you had already select a database you can only use Show tables to show all the tables in the database. For ex. Select database MySql and in Sql command window enter following text SHOW TABLES And click on Run. It will show all the tables which is avalible in the list

How to take back up of my sql database using C#

Image
You can also download running code. Taking a back up of my sql using C# is very easy but this also be termed as tricky backup. Like Sql server my sql does not provide built in stored procedures to take back up. For back up my sql use a Exe file named “mysqldump.exe” You will find this Exe file in “C:\Program Files\MySQL\MySQL Server 5.0\bin” folder of mySql. This file takes so many parameters for different options. But my task is to simply take a backup of single database To take a backup of single database following are the parameters mysqldump -u<usernane> -p <password> -h<servername or ip> <databasename> > <localtion to take backup> Please let me know if this helps you to perform your task easily.

Auto Complete Example in Asp.net C# Using JQuery

Image
Download Running Code Supporting JQuery Before writing this post I had written one another post which is using a pure JavaScript to show Auto complete or Auto delete example. My previous example is not using Jquery which is a famous and reliable way to present your data. One of the drawback of my previous example is it will become slow as I have to load a bulk data for auto complete box. I had received many comments on this post, some of them had appreciated and some of them had suggested using Jquery. One of my great readers had given an example of Jquey which I am posting to help you all. So, before posting this example I would like to say thanks to my reader Eng. Mohammed Ibrahim who had suggested and helped me to help others.

How to send e-mail using C# with Attachment

When I am working in core asp mail sending is one of the biggest task. For mail sending I have to check for third party on server. I have to according to third party avalibale on different server. But, now say thanks to Microsoft who had made that task easy. Sending a email using ASP.NET 2.0 and C# 2.0 is actually very simple. First, you will need to import the System.Net.Mail namespace. The System.Net.Mail namespace contains the SmtpClient and MailMessage Classes that we need in order to send the email. You have to write this code to your page. public static void Send(string SMTPServerName, string SMTPUserName, string SMTPPassWord, string MailFrom, string MailTo, string CC, string BCC, string Subject, string Body, bool BodyHTML, string Attachment) { MailMessage message = new MailMessage(MailFrom, MailTo, Subject, Body); /******************************************/ //Adding multiple To Addresses foreach (string sTo...

How to Make Windows Service Using C# 2008

Image
I have an task to run a Stored procedure after every 30 minutes. My first choice is to create a job on Sql server. But I also have to write a log file along with the stored procedure. Now, my choice will be Windows service. Creating a windows service is a very easy task but how to deply...... let me explain how to work with windows service. Creating a program that can run in the background of the operating system has any benefits, this is very important as the program can run without a graphic user interface. Complex service that are to run are longer time, and without the need the user to login the system. Windows services are harder to develop, debug, and test. But if you software are to run in server that require to start up automatically with the server is turn on, Windows service is your choice. Creating your skeleton project in Visual Studio 2008 To create a Windows Service project in Visual Studio 2008, you must select from the Visual C# Windows Projects. Give your Windows Servi...

User Defined Functions in Microsoft Sql Server

With SQL Server 2000, Microsoft has introduced the concept of User-Defined Functions that allow you to define your own T-SQL functions that can accept zero or more parameters and return a single scalar data value or a table data type. As every one knows the importance of User defined functions. So, while using Sql Server 7. We have repeat a same code for many number of times. Following is the description about Use Defined Functions which we can create. There are three types of User-Defined functions in SQL Server 2000 and they are Scalar, Inline Table-Valued and Multi-statement Table-valued. How do I create and use a Scalar User-Defined Function? A Scalar user-defined function returns one of the scalar data types. Text, ntext, image and timestamp data types are not supported. These are the type of user-defined functions that most developers are used to in other programming languages. You pass in 0 to many parameters and you get a return value. Below is an example that is based in the d...