Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 更新以使用给定月份的第一个_Sql_Advantage Database Server - Fatal编程技术网

Sql 更新以使用给定月份的第一个

Sql 更新以使用给定月份的第一个,sql,advantage-database-server,Sql,Advantage Database Server,我没有这方面的SQL示例,但是使用Advantage Architect。我有一张桌子,上面有年份(如2017年),还有月份(如04年)。 我想更新另一个表(在我已经标识的字段上使用内部联接,所以不必担心该位),使之成为dd/mm/yyyy格式的日期,并使用上面提到的另一个表中的月份和年份,将使用的每个日期的日期更新为01 ADS提供的日期处理功能有些有限。最容易使用的日期格式似乎是YYYY-MM-DD,但是要将列转换为您要查找的日期会有点复杂 这里有一个例子可以帮助你解决问题 create t

我没有这方面的SQL示例,但是使用Advantage Architect。我有一张桌子,上面有年份(如2017年),还有月份(如04年)。 我想更新另一个表(在我已经标识的字段上使用内部联接,所以不必担心该位),使之成为dd/mm/yyyy格式的日期,并使用上面提到的另一个表中的月份和年份,将使用的每个日期的日期更新为01


ADS提供的日期处理功能有些有限。最容易使用的日期格式似乎是
YYYY-MM-DD
,但是要将列转换为您要查找的日期会有点复杂

这里有一个例子可以帮助你解决问题

create table #temp (calyear numeric(4, 0), calmonth numeric(2,0));
insert into #temp (calyear, calmonth) values (2017, 10);
insert into #temp (calyear, calmonth) values (2017, 7);

/* 
  Start convoluted workaround here. Cast the result of the concatenation below 
  (which creates a string in the format 'YYYY-MM-DD') into a date value
*/
select cast(txtdate as SQL_DATE) as newdate from 
(
  /* 
     Concatenate year, month (adding leading zero if needed to make two-digit)
     and month
  */
  select 
    trim(cast(calyear as SQL_Char)) + '-' + 
    right('00' + trim(cast(calmonth as SQL_Char)), 2) + 
    '-01' as txtdate from #temp
) t;

请向我们展示您的示例数据,并让我们知道您正在使用什么RDBM。请考虑发布表的DDL。好的,我使用Advantage Architect SQL,我在表1下面的两列(CalendarYear、CalendarMonth)下面放了一个,我需要用它插入或更新另一个表(表2)中的一列(有效),这是一个日期字段,但要添加到该01中,用于每个日期的日期。连接来自表1中的一列,与表2中的相同,但我不能在这里显示,因为它是敏感信息。