Click here to Skip to main content
15,914,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,


My Query:
C#
strQry = "Select Sitecode,Type,SpeedLimit,Triggerspeed from TBL_TXN_XML_DATA where rtrim(Sitecode) = '" + cmbsitewise.Text.Trim() + " ' and rtrim(Type) = '" + cmbtypewise.Text.Trim() + "'and rtrim(SpeedLimit) = cast(speedlimit as numeric),0)-cast(triggerspeed as numeric),0) '" + txtspeedlimit.Text.Trim() + "' and rtrim(TriggerSpeed) = '" + cmbtriggerspeed.Text.Trim() + "'and  rtrim(FileTime) = '" + cmbfiletime.Text.Trim() + "'  group by Sitecode,Type,SpeedLimit,Triggerspeed 

My database:
Speedlimit Triggerspeed
50 65 so different is 15

i Enter the speedlimit value in my text box is >10 that time i need this output


sitecode
Type
speedlimit-50
Triggerspeed-65

how to write query in this output.pls help
Posted
Updated 19-Feb-13 21:39pm
v2
Comments
Singh Vijay Kumar 20-Feb-13 3:39am    
Not Clear, Plus please paste your actual query (final value of strQry).

Look at your query.
Let's just cut it down a bit and do some substitutions:
SQL
Select Sitecode,Type,SpeedLimit,Triggerspeed from TBL_TXN_XML_DATA where
   Sitecode = 'SITE' and 
   Type = 'TYPE' and 
   SpeedLimit = 50-65 '50' and 
   TriggerSpeed = '65' and  
   FileTime = 'TIME'  
group by Sitecode,Type,SpeedLimit,Triggerspeed
So, your speed limit is negative...


But stop right there!
Look at your speedlimit clause:
SQL
rtrim(SpeedLimit) = cast(speedlimit as numeric),0)-cast(triggerspeed as numeric),0) '" + txtspeedlimit.Text.Trim() + "'
So this only matches when the trigger speed is zero...

And for goodness sake:
1) Don't store numeric values as strings - store them as numbers. They are much, much easier to work with if you do that.
2) Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
Share this answer
 
Comments
Anurag Sinha V 20-Feb-13 4:04am    
A very detailed explanation Mr. OriginalGriff.Hats off... :)

Regards
Anurag
Thanks for your mail Mr.OriginalGriff.. Thank u so much
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900