如何创建临时主键Azure TSQL服务器
我需要检查名为User的表中可能存在的重复地址。为此,我使用连接,然后比较地址字符串中第一组街道编号的表。例如,“123 First Street”和“123 First St.”需要标识为可能的匹配/重复项 但是,我还需要显示记录的Telerik RadGrid具有唯一的DataKeyName来标识行,以便双击javascript函数工作 由于连接,我的普通主键在“两个”表a和b中都是重复的。如何使用SQL创建临时psuedo主键,以便datagrid能够识别双击的行如何创建临时主键Azure TSQL服务器,sql,tsql,telerik,radgrid,Sql,Tsql,Telerik,Radgrid,我需要检查名为User的表中可能存在的重复地址。为此,我使用连接,然后比较地址字符串中第一组街道编号的表。例如,“123 First Street”和“123 First St.”需要标识为可能的匹配/重复项 但是,我还需要显示记录的Telerik RadGrid具有唯一的DataKeyName来标识行,以便双击javascript函数工作 由于连接,我的普通主键在“两个”表a和b中都是重复的。如何使用SQL创建临时psuedo主键,以便datagrid能够识别双击的行 try
try
{
//Select Query to populate the RadGrid.
string selectQuery =
"SELECT " +
//We rename the dbo.User table as "a" then rename it again as "b" so we can look for duplicate Street Address numbers
"a.Id AS LeftID,a.DateSubmitted AS LeftDateSubmitted,a.Updated AS LeftUpdated," +
"a.Status AS LeftStatus,a.StreetAddress AS LeftStreetAddress," +
"b.Id AS RightID,b.DateSubmitted AS RightDateSubmitted,b.Updated AS RightUpdated," +
"b.Status AS RightStatus,b.StreetAddress AS RightStreetAddress " +
//We join the 2 virtual dbo.User tables where table b Id's are greater than table a meaning b records are newer
"FROM [User] a JOIN [User] b ON b.Id > a.Id AND " +
//LEFT selects the left most characters (usually numbers) in the StreetAddress field string before the space ' '
//and eliminates the rest of the address isolating just the street address numbers for matching
"LEFT(a.StreetAddress,CHARINDEX(' ',a.StreetAddress)) = LEFT(b.StreetAddress,CHARINDEX(' ',b.StreetAddress)) " +
//Don't show orange or blue status records
"AND b.Status != 'Orange' AND a.Status != 'Orange' AND a.Status != 'Blue' AND b.Status != 'Blue' " +
//If a b record (newer) is red then ignore because it is completed and ignore a records (oldest) older than 90 days
"WHERE a.DateSubmitted >= (GetDate() - 90) AND b.Status != 'Red' " +
//Show newest records first
"ORDER BY b.DateSubmitted DESC"
;
SqlDataAdapter.SelectCommand = new SqlCommand(selectQuery, SqlConnection);
SqlDataAdapter.Fill(dtTable);
RadGrid1.DataSource = dtTable;
如果只想为每行生成一个随机ID,请将NEWID()函数添加到列列表中 例如:
选择NEWID()作为PsuedoKey,*FROM…如果您只想为每行生成一个随机ID,请将NEWID()函数添加到列列表中 例如:
选择NEWID()作为PsuedoKey,*FROM…这看起来很不错@dgiard我会尝试一下并让您知道。谢谢你太棒了,先生!谢谢@dgiard!这看起来很不错@dgiard我会试试看,然后告诉你。谢谢你太棒了,先生!谢谢@dgiard!