is there way use defined column name in select statement clause? here t-sql codes,
select convert(datetime,( case when operator = 't' (substring(senddate,7,4)+'-'+substring(senddate,4,2)+'-'+ substring(senddate,1,2) + substring(senddate,11,9)) else recivedsms.senddate end)) defineddate datepart(wk, defineddate) = 52
yours affectionately , thank helps, now.
edited part of posted
create table #temp ( datefield datetime, numberfield varchar(10), sender varchar(255) ) insert #temp select distinct( convert(datetime, ( case when operator = 't' ( substring( senddate, 7, 4 ) + '-' + substring( senddate, 4, 2 ) + '-' + substring( senddate, 1, 2 ) + substring( senddate, 11, 9 ) ) else senddate end))) table1.datefield, substring(table1.message,7,7) numberfield table1 inner join table2 on table1.sender = table2.phonenumber, ( select convert(datetime, ( case when operator = 't' ( substring( senddate, 7, 4 ) + '-' + substring( senddate, 4, 2 ) + '-' + substring( senddate, 1, 2 ) + substring( senddate, 11, 9 ) ) else senddate end)) defineddate table1 table1.operator not null ) q operator not null , substring(table1.message,1,6) = 'tree st' , datepart( wk, q.defineddate ) = 52 , datepart(year, q.defineddate ) = 2010 select * #temp order numberfield drop table #temp
not directly wrap in subselect.
sql statement
select * ( select convert(datetime, ( case when operator = 't' ( substring( senddate, 7, 4 ) + '-' + substring( senddate, 4, 2 ) + '-' + substring( senddate, 1, 2 ) + substring( senddate, 11, 9 ) ) else recivedsms.senddate end)) defineddate yourtable ) q datepart( wk, defineddate ) = 52
update
i believe following equivalent wrote:
select q.defineddate , q.numberfield ( select sender , numberfield = substring(table1.message, 7, 7) , operator , convert( datetime , ( case when operator = 't' substring( senddate, 7, 4 ) + '-' + substring( senddate, 4, 2 ) + '-' + substring( senddate, 1, 2 ) + substring( senddate, 11, 9 ) else senddate end )) defineddate table1 table1.operator not null ) q inner join table2 on table2.phonenumber = tabl1.sender q.numberfield 'tree st%' , datepart( wk, q.defineddate ) = 52 , datepart( year, q.defineddate ) = 2010
Comments
Post a Comment