Roughly as follows: Since the database design is not very reasonable, and EPS through stock price to calculate the PE, so the first time is more like a function, this function as a column, can be displayed easily.
using (SqlConnection conn
SqlDataReader datareader = cmd.ExecuteReader ();
}
string columnName = “”;
conn.Open ();
tableName = “StockPriceSZ_SP”;
}
using System.Data;
1: VS2008 to create a database SqlServer project
string tableName = “”;
{
so similar, but the exec function does not allow food and other kind of statement. so at a loss. remorse original design table is too casual.
2: Create a class code code code that makes up the stock by judge Remove the corresponding SQL statement date stock price
RECONFIGURE;
{
public partial class UserDefinedFunctions
columnName = “sz” StockCode;
decimal result = 0;
However, due to improper design database, this function needs to generate the statement that I need to write the function in EXEC SP_EXECUTESQL @ STR
CREATE FUNCTION [dbo]. [ufn_StockPrice] (@ StockCode nvarchar (6 ), @ ReportTime nvarchar (10))
FROM : \ Chengxu \ Modules.dll — dll location for
result = Convert.ToDecimal (datareader.GetValue (0). ToString () );
public static SqlMoney ufn_StockPrice (string StockCode, string ReportTime)
4: Use the time you can use this function select StockCode, ReportTime, [dbo]. [ufn_StockPrice] (StockCode, ReportTime), * FROM ***
sp_configure lr enabled 1; – open database CLR
3: (can be deployed to the corresponding database, provided that the solution properties of the configuration, the connection string)
GO
AS
using Microsoft.SqlServer.Server;
}
— Custom number of rows bound to dl the corresponding method.
= new SqlConnection (“context connection = true”))
drop ASSEMBLY [Modules]
else
solve the problem.
EXTERNAL NAME [Modules]. UserDefinedFunctions.ufn_StockPrice
{
using System.Data.SqlTypes;
[Microsoft.SqlServer.Server.SqlFunction (DataAccess = DataAccessKind.Read)] < br /> if (prex == “6″)
tableName = “StockPriceSH_SP”;
columnName = “sh” StockCode;
2010 年 06 月 20 日
GO < br /> CREATE ASSEMBLY [Modules]
out when the program encounters a problem. Environment VS2008 SQL2005
{
SqlCommand cmd = new SqlCommand [original] credit card no annual fee for life can be? Bank is somewhat non-permissive _ credit card information (“SELECT ISNULL ([" columnName "], 0) FROM [" tableName "] WHERE PDATE = quot; ReportTime ” “, conn);
};
also be able to compile. The compiled dll file saved to a location
by using C # CLR can solve the database can not solve the problem.
{
RETURNS money
prex = StockCode.Substring (0, 1);
Pan brother later found a solution.
}
using System.Data.SqlClient;
if (datareader.Read ())
return result;
string prex = “”;
}
WITH PERMISSION_SET = SAFE
{
using System;
Note: If an error occurs, increase the database compatibility mode, then run, then compatibility mode to change back to OK .