|
Anything wrong with google today?
Have a look here[^].
String concatenation has been around as long as SQL has. But different dialects have different syntax.
Oracle uses '||', Sql Server uses '+', most implementations can use 'concat(string1, string2)' but not SQL Server AFAIK. Could be wrong about that though.
|
|
|
|
|
Jörgen Andersson wrote: Anything wrong with google today?
Same impression here, I'm starting to believe I'm the only person with Google access today
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
Hi,
In MySQL, how can I format a number like this
1000000001
where the first 1 is the weekday and the last one is my LAST_INSERT_ID and I am adding just zeroos to make it always 10 digits?
|
|
|
|
|
How about this:
SELECT (DAYOFWEEK(NOW()) * 1E9) + @@LAST_INSERT_ID
|
|
|
|
|
Hi,
I want to update the column TID with the top most value of TID as long as MID is the same number.
I want to do this (table after update)
PID SID TID MID RID
3 0 0 4 1
3 NULL 0 4 2
3 NULL 0 4 3
3 NULL 0 4 4
3 NULL 0 4 5
3 NULL 0 4 6
3 NULL 0 4 7
3 4 4 8 1
3 NULL 4 8 2
3 NULL 4 8 3
3 NULL 4 8 4
Below is the actual table before update.
PID SID TID MID RID
3 0 0 4 1
3 NULL NULL 4 2
3 NULL NULL 4 3
3 NULL NULL 4 4
3 NULL NULL 4 5
3 NULL NULL 4 6
3 NULL NULL 4 7
3 4 4 8 1
3 NULL NULL 8 2
3 NULL NULL 8 3
3 NULL NULL 8 4
Any suggestion/solutions deeply appreciated.
Thanks
|
|
|
|
|
Assuming your DB is SQL Server, you can try this (just out of mind, not tried though)
UPDATE MyTable A SET A.TID = (SELECT MAX(B.TID) FROM MyTable B WHERE A.MID = B.MID)
|
|
|
|
|
Thanks for your help.
I have solved it by creating a view of all 'Not NULL' (top most) rows . Then created a stored proc to loop through the view and update the TID. A long procedure though but it did work.
Cheers !
|
|
|
|
|
I think you want to do something like this ...
update table A
set tid =
(select max(tid)
from TableA
Group By mid)
Check these for references:
http://msdn.microsoft.com/en-us/library/ms177523.aspx
http://data.bangtech.com/sql/sql_update_with_correlated_subquery.htm
|
|
|
|
|
Hi thanks for your solution and links,
But your query returned an error.
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
|
|
|
|
|
That's because he forgot a small but important condition.
Try this:
update table A as a1
set tid =
(select max(tid)
from TableA as A2
Where A1.mid = A2.mid
Group By mid)
|
|
|
|
|
Thanks for the refinement to my SQL. Sometimes when you don't have the actual data to test with, you forget some stuff.
|
|
|
|
|
David Mujica wrote: Sometimes when you don't have the actual data to test with, you forget some
stuff.
Tell me about it. That's almost something I can put in my CV.
|
|
|
|
|
Hi everybody,
I have some numbers. Numbers are
(
0
234,9
-27
0
-55,9
0
0
-59
0
100,72
-26
0
-25,72
0
0
0
-82
0
0
0
0
0
0
-134)
I want to this.
SELECT SUM(FIELDX) FROM TBLX
but result is returning (-2,8421709430404007E-14)
actually resutl is 0 (Zero)
How can i solve this problem?
Thanks.
Başak Öner
|
|
|
|
|
Basak Oner wrote: actually resutl is 0 (Zero)
Not if you're a computer, then it's "almost 0". Try rounding the result.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
sorry I don't understand your message.
I need your detailed explanation.
Thanks.
|
|
|
|
|
Basak Oner wrote: sorry I don't understand your message.
Try the ROUND function. This is due to how computers work and how they calculate. You know what a fractional number is, but they do not exist within a computer.
Basak Oner wrote: I need your detailed explanation.
You're not in school anymore. There's an explanation here[^], good luck.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for your free time.
|
|
|
|
|
You actually *read* it?
Ehr.. you're welcome, and yes, well done
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
You can try to change the datatype of the field.
Check if SELECT SUM(cast(FIELDX as numeric(5,2)) FROM TBLX works.
In your real data you naturally need to adjust the precision and scale of the numeric field to fitting values.
|
|
|
|
|
Hi Experts
I have a query which needs to return the second in Day, Hour, Minute, Second format.
The below code works fine when its less than a day, but does not work, when the value in second is greater than a day
PRINT Convert(VarChar, DateAdd(S, 86400, 0), 108)
86400 is exactly a day and it returns 00:00:00
Can someone modify it and show me the result something like this
1:00:00:00.
Thanks
|
|
|
|
|
Take a look at MODULO from BOL!
SELECT 38 / 5 AS Integer, 38 % 5 AS Remainder ;<br />
Use a case statement to detect if it is over 86399 and apply the appropriate formula. If you use it in multiple places then create your own UDF.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Try the option, CONVERT(VARCHAR(10),'fieldname',112)
|
|
|
|
|
Try replying to the op next time, he will not get notification when you reply to me!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
try this :
DECLARE @DurationSeconds INT
DECLARE @DurationDays INT
SET @DurationSeconds = 62110
SET @DurationDays = @DurationSeconds /86400
Select CASE WHEN @DurationDays > 0 THEN
Convert(VarChar,@DurationDays)+ ':'+
Convert(VarChar, DateAdd(S, (@DurationSeconds-(@DurationDays*86400)),0), 108)
ELSE
Convert(VarChar, DateAdd(S, @DurationSeconds, 0), 108)
END
|
|
|
|
|
Using Sql 2000 and C#.
I have a stored procedure where I pass in my identifier and use it to select a set of rows from several tables. When I execute this SP in query analyzer it works great, returning only the rows that do not exist in @Data. When executed in C# it is returning the entire set of data relevant to that identifier.
I'm at a loss on this. I've spent hours changing the SP around trying to get different results. I've tried both temp tables and var tables with the same results. Again, it always works in QA but never in C#.
Any thoughts? I've shortened some of the repetitive data from this query to save on screen space (and your eyes) but let me know if there is anything else i can show that could help.
Also, here's the weird part. I have a near exact duplicate of this query that works in both C# and QA. The only difference is that #Chas is populated via a select statement that returns a range of values instead of just being populated by the passed in value. I know i don't have to insert this value into #Chas but instead could just compare directly against it. It was like this just to make it as identical to the original as possible since the original works.
USE [B_D_DashPanel]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[sp_BD_PermConflicts_Chassis_Only]
@Chassis_Search nvarchar(50)
AS
Declare @Data TABLE(
Chassis nvarchar(50),
ItemC nvarchar(50),
Location nvarchar(50),
Panel nvarchar(13),
Part nvarchar(50)
)
Create TABLE #Chas (
Chassis_No nvarchar(50)
)
set nocount on
insert into #Chas (Chassis_No) values (@Chassis_Search)
insert into @Data (Chassis, ItemC, Location, Panel, Part)
select distinct WorkPlacementorder.salesorderno, workplacementorder.itemcode, workplacementorder.location, workplacementorder.panel,
itembompn.partnumber1
from #Chas, workplacementorder
join itembompn
on workplacementorder.itemcode = itembompn.itemcode
inner join chassisdb.dbo.tblopenjit
on workplacementorder.salesorderno = chassisdb.dbo.tblopenjit.chassisnbr
where chassisdb.dbo.tblopenjit.chassisnbr like #Chas.Chassis_No and chassisdb.dbo.tblopenjit.itemid = itembompn.partnumber1
and WorkPlacementorder.salesorderno like #Chas.Chassis_No
SELECT b_d_Dashpanel.dbo.workplacementorder.ItemCode, b_d_Dashpanel.dbo.items.itemdescription
FROM #Chas, B_D_DashPanel.dbo.WorkPlacementOrder join b_d_Dashpanel.dbo.items on b_d_Dashpanel.dbo.workplacementorder.itemcode = b_d_Dashpanel.dbo.items.itemcode
where salesorderno = Chassis_No and b_d_DashPanel.dbo.workplacementorder.itemcode not in (select itemc from @Data)
drop table #Chas
|
|
|
|