Posts

Showing posts from February, 2016

Type Declaration Instruction in C

Type Declaration Instruction This instruction is used to declare the type of variables being used in the program. Any variable used in the program must be declared before using it in any statement. The type declaration statement is written at the beginning of main( ) function. Ex.: int bas ; float rs, grosssal ; char name, code ; There are several subtle variations of the type declaration instruction. These are discussed below: While declaring the type of variable we can also initialize it as shown below. int i = 10, j = 25 ; float a = 1.5, b = 1.99 + 2.4 * 1.44 ; The order in which we define the variables is sometimes important sometimes not. For example, int i = 10, j = 25 ; is same as int j = 25, j = 10 ; However, float a = 1.5, b = a + 3.1 ; is alright, but float b = a + 3.1, a = 1.5 ;         is not. This is because here we are trying to use a even before defining it. The following statements would work int a, b, c, d ; a = b = ...

Instructions to write a C program

C Instructions Now that we have written a few programs let us look at the instructions that we used in these programs. There are basically three types of instructions in C: Type Declaration Instruction Arithmetic Instruction Control Instruction The purpose of each of these instructions is given below:       a)       Type declaration instruction To declare the type of variables used in a C program.       b)       Arithmetic instruction To perform arithmetic operations between constants and variables.       c)       Control instruction To control the sequence of execution of various statements in a C program. C programs would usually contain only the type declaration and the arithmetic instructions.

SQL_VARIANT_PROPERTY Function

SQL_VARIANT_PROPERTY (Transact-SQL) This functions returns the base data type and other information about a   sql_variant   value. Syntax SQL_VARIANT_PROPERTY ( expression , property ) Arguments expression Is an expression of type   sql_variant . property Contains the name of the   sql_variant   property for which information is to be provided.   property   is   varchar( 128 ) , and can be any one of the following values. Value Description Base type of sql_variant returned BaseType SQL Server data type, such as: bigint binary char date datetime datetime2 datetimeoffset decimal float int money nchar numeric nvarchar real smalldatetime smallint smallmoney time tinyint uniqueidentifier varbinary varchar sysname NULL = Input is not valid. Precision Number of digits of the numeric base data type: ...

IDENTITY (Function)

Image
IDENTITY (Function) Is used only in a SELECT statement with an INTO table clause to insert an identity column into a new table. Although similar, the IDENTITY function is not the IDENTITY property that is used with CREATE TABLE and ALTER TABLE. Note To create an automatically incrementing number that can be used in multiple tables or that can be called from applications without referencing any table, see Sequence Numbers. Syntax  IDENTITY (data_type [ , seed , increment ] ) AS column_name Arguments data_type Is the data type of the identity column. Valid data types for an identity column are any data types of the integer data type category, except for the bit data type, or decimal data type. seed Is the integer value to be assigned to the first row in the table. Each subsequent row is assigned the next identity value, which is equal to the last IDENTITY value plus the increment value. If neither seed nor increment is specified, both default to 1. increment ...

IDENT_SEED Function

Image
IDENT_SEED  This function returns the original seed value (returned as numeric(@@MAXPRECISION,0)) that was specified when an identity column in a table or a view was created. Changing the current value of an identity column by using DBCC CHECKIDENT does not change the value returned by this function. Syntax  IDENT_SEED ( 'table_or_view' ) Arguments ' table_or_view ' Is an expression that specifies the table or view to check for a identity seed value. table_or_view can be a character string constant enclosed in quotation marks, a variable, a function, or a column name. table_or_view is char, nchar, varchar, or nvarchar . Return Types numeric Exceptions Returns NULL on error or if a caller does not have permission to view the object. In SQL Server, a user can only view the metadata of securables that the user owns or on which the user has been granted permission. This means that metadata-emitting, built-in functions such as IDENT_SEED may return...

IDENT_INCR Funtion

Image
IDENT_INCR Funtion This function returns the increment value (returned as numeric (@@MAXPRECISION,0)) specified during the creation of an identity column in a table or view that has an identity column. Syntax  IDENT_INCR ( 'table_or_view' ) Arguments ' table_or_view ' Is an expression specifying the table or view to check for a valid identity increment value. table_or_view can be a character string constant enclosed in quotation marks, a variable, a function, or a column name. table_or_view is char, nchar, varchar, or nvarchar. Return Types numeric Exceptions Returns NULL on error or if a caller does not have permission to view the object. In SQL Server, a user can only view the metadata of securables that the user owns or on which the user has been granted permission. This means that metadata-emitting, built-in functions such as IDENT_INCR may return NULL if the user does not have any permission on the object. For more information, see Meta...

IDENT_CURRENT function

Image
IDENT_CURRENT  This function returns the last identity value generated for a specified table or view. The last identity value generated can be for any session and any scope. Syntax IDENT_CURRENT( 'table_name' ) Arguments table_name Is the name of the table whose identity value is returned.    table_name is varchar, with no default. Return Types numeric(38,0) Exceptions Returns NULL on error or if a caller does not have permission to view the object. In SQL Server, a user can only view the metadata of securables that the user owns or on which the user has been granted permission. This means that metadata-emitting, built-in functions such as IDENT_CURRENT may return NULL if the user does not have any permission on the object. For more information, see Metadata Visibility Configuration. Remarks IDENT_CURRENT is similar to the SQL Server 2000 identity functions SCOPE_IDENTITY and @@IDENTITY. All three functions return last-generated ide...

How to compare identity values returned by IDENT_CURRENT, @@IDENTITY and SCOPE_IDENTITY?

Image
Comparing identity values returned by IDENT_CURRENT, @@IDENTITY and SCOPE_IDENTITY The following example shows the different identity values that are returned by IDENT_CURRENT, @@IDENTITY, and SCOPE_IDENTITY.

How to return the last identity value generated for a specified table?

Returning the last identity value generated for a specified table: Following example returns the last identity value generated for the Person.Address table in the AdventureWorks2012 database. USE AdventureWorks2012; GO SELECT IDENT_CURRENT ('Person.Address') AS Current_Identity; GO OR Following example returns the last identity value generated for the College: USE College; GO SELECT IDENT_CURRENT ('Student') AS Current_Identity; GO

DATALENGTH Function

DATALENGTH (Transact-SQL) This function returns the number of bytes used to represent any expression. Syntax  DATALENGTH ( expression )  Arguments expression Is an expression of any data type. Return Types bigint if expression is of the varchar(max), nvarchar(max) or varbinary(max) data types; otherwise int . Remarks DATALENGTH is especially useful with varchar, varbinary, text, image, nvarchar, and ntext data types because these data types can store variable-length data. The DATALENGTH of NULL is NULL. Note Compatibility levels can affect return values. For more information about compatibility levels, see ALTER DATABASE Compatibility Level (Transact-SQL). Examples The following example finds the length of the Name column in the Product table. USE AdventureWorks2012; GO SELECT length = DATALENGTH(Name), Name FROM Production.Product ORDER BY Name; GO OR This following example find the length of ID column in Student table: SELECT length ...

Data Type Functions

Data Type Functions (Transact-SQL) Data type functions return information about various data type values. In This Section we read the following scalar functions: DATALENGTH (Transact-SQL) IDENT_SEED (Transact-SQL) IDENT_CURRENT (Transact-SQL) IDENTITY (Function) (Transact-SQL) IDENT_INCR (Transact-SQL) SQL_VARIANT_PROPERTY (Transact-SQL)

Instructions to write C Program

C Instructions Now that we have written a few programs let us look at the instructions that we used in these  programs. There are basically three types of instructions in C: Type Declaration Instruction Arithmetic Instruction Control Instruction The purpose of each of these instructions is given below:      Type declaration instruction To declare the type of variables used in a C program.             Arithmetic instruction To perform arithmetic operations between constants and variables.             Control instruction To control the sequence of execution of various statements in a C program. Since, the elementary C programs would usually contain only the type declaration and the arithmetic instructions; we would discuss only these two instructions at this stage. The other types of instructions would be discussed in det...