You can do this with a cross join to another table.
declare @tblA table( id int, tot int)
declare @tblB table( id int)
declare @tot table (tot int)
insert @tblA values( 1, 2)
insert @tblA values( 2, 3)
insert @tot values( 1)
insert @tot values( 2)
insert @tot values( 3)
insert @tblB...
Any codelonger that a single statement in an IF… ELSE block needs to be contained within BEGIN and END statements so you get
IF <condition>
BEGIN
<some code>
END
ELSE
BEGIN
<some other code>
END
Also the second IF statement (“if @dbname = 'scheme'”) will overwrite the correct string...
I think a case statement similar to this should give you the results you want.
SELECT ID,
LoginName,
CASE WHEN Password1 = 'Pass' THEN 'Password1 Match'
WHEN Password2 = 'Pass' THEN 'Password2 Match'
WHEN Password3 = 'Pass' THEN 'Password3 Match'...
Probably the easiest way of renaming an object is to use sp_rename. For a column you would use some thing like this.
EXEC sp_rename 'ColumnName', 'NewName', 'COLUMN'
Have just had a similar problem with a very different query. We found the problem only occurred where service pack 3 hadn’t been installed on the client. Hope this helps.
This can be done using a DTS package, the simplest way is to change the transform data task in your package. Rather than outputting directly from the table use an SQL query similar to this,
Select 'point' Point, A, B from tbl
Which will give you, an additional column word point for every row in...
This should work.
UPDATE dbo.[tblGlobal_Availability]
SET dbo.[tblGlobal_Availability].[Dirty Price] =SecurityData.[price]
FROM dbo.[tblGlobal_Availability] Availability
LEFT OUTER JOIN dbo.[tblGSP55S9X - Security Data] SecurityData
ON Availability.Isin =SecurityData.ISIN
WHERE...
You can't use IF's in this way, what's need is a CASE statment. Though this can also be done with an ISNULL function depending on your data.
If you have null's in BB where there is no value then use IsNull.
Select IsNull( BB, AA) *CC From tbl
However if you have 0 in BB where there is no value...
I think this should do what you want, but you may find it runs slowly if you’re working on lots of data.
update table3
set table3.approver = s1.approver
from table3 t3
inner join (
select req_id, approver
from table1 t1
cross join table2 t2...
I need to Create a list of column names output by a view. Not a problem using sysobjects and syscolumns. The problem is that I also need to get the tablename for where each column comes from. i.e. if I had the following as a view
Select Person.DomicileId, Person.PersonId from Person Inner Join...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.