English 中文(简体)
更新记录中无效列的第一行条目
原标题:Update first row entry of a null column of a record

我有一个表格,其中列有 Userid , Email mobile Email 没有无效值,但 mobile 在表格中各行都有空号。

我想用独有的 mobile 来更新每行的首行。 我希望这有用, 但不确定 。

UPDATE       userprofileplus
SET                mobile = 9199225533
WHERE        (UserId IN
                             (SELECT        TOP (1) UserId
                               FROM            userprofileplus AS userprofileplus_1
                               WHERE        (mobile IS NULL) AND (UserId = 5)))

我的目的是防止用户在表格上出现不必要的空格。我注意到一个问题,那就是 SQL 服务器的 Contaction < strong > 版不支持 TOP 关键字。 我如何处理这个?

SQL SQL 服务器 CE 版本为 4. 0. 。 我还注意到, < code> TOP 关键词得到了WebMatrix的完全支持, 但 VS 2010 SP1 拒绝SQL Server CE 4. 这里的 < code> TOP 关键词支持 。 这里发生了什么? 当在网络矩阵中运行时, 所有无移动的记录都会被更新, 忽略TOP 标准 。 我只需要更新第一个返回的行, 而不是全部更新。 我也尝试过这个结果 。

UPDATE       userprofileplus
SET                mobile = 9199225533
WHERE        (UserId IN
                             (SELECT        UserId
                               FROM            userprofileplus AS userprofileplus_1
                               WHERE        (mobile IS NULL) AND (UserId = 5) order by userid offset 1 rows))

来人啊 保释我出去

最佳回答

......我终于得到了它 经过几次逻辑的潜水。

UPDATE       userprofileplus
SET                mobile = 9199225533
WHERE        (mobile is null and userid = 5) and (Id IN
                             (SELECT        TOP (1) Id
                               FROM            userprofileplus AS userprofileplus_1
                               WHERE        (mobile IS NULL) AND (UserId = 5)))

I had to use my primary key column as a pivot to ensure a single row is returned from the subquery even though i was using a TOP criteria. But i m still curious why VS2010 sqlCE 4.0 does not support the TOP keyword but webmatrix does.Also, whats the reason why all columns where updated even after using the TOP keyword in the other queries?

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签