Monday, March 19, 2012

Access Val Function in SQL Server

What is the counterpart of this function when using SQL Server 2000? Imgetting this error "System.Data.SqlClient.SqlException: 'Val' is not arecognized function name"
What do I have to change in my queryString?
SELECT ASP_MainForm.UserID, Val([FormNo]) AS Expr1,ASP_MainForm.DateCreated, ASP_MainForm.DateNeeded,ASP_MainForm.FormStatus, ASP_MainForm.Print, ASP_MainForm.PRNo,ASP_MainForm.ForUse, [FirstName]+' '+[LastName] AS CompName FROMASP_MainForm INNER JOIN CEN_USERS ON ASP_MainForm.UserID =CEN_USERS.UserBadgeNo WHERE(((ASP_MainForm.FormStatus)<>'Approved') AND((ASP_MainForm.ForUse)<>'Test')) ORDER BY Expr1 DESC
Pls help thanks
Use SQL Server's Convert Function. Convert(decimal(10,5), [FormNo])

CONVERT(data_type[(length)],expression [,style])

Arguments

expression

Is any valid Microsoft? SQL Server? expression. For more information, seeExpressions.

data_type

Is the target system-supplied data type, includingbigint andsql_variant. User-defined data types cannot be used. For more information about available data types, seeData Types.

length

Is an optional parameter ofnchar,nvarchar,char,varchar,binary, orvarbinary data types.

style

Is the style of date format used to convertdatetime orsmalldatetime data to character data (nchar,nvarchar,char,varchar,nchar, ornvarchar data types), or the string format when convertingfloat, real,money, orsmallmoney data to character data (nchar,nvarchar, char,varchar,nchar, ornvarchar data types).

SQL Server supports the date format in Arabic style, using Kuwaiti algorithm.

In the table, the two columns on the left represent thestyle values fordatetime orsmalldatetime conversion to character data. Add 100 to astyle value to get a four-place year that includes the century (yyyy).

|||Thanks! That was indeed the solution to it. Thanks again.

No comments:

Post a Comment