简体   繁体   中英

Debugging SQL Server queries

I have a view which has started causing the following error:

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'R1500051' to data type int.

The problem is, the query is quite big and complex (several sub queries, joins and function calls) and I have no idea where that error is actually coming from. I've tried commenting bits out but that doesn't really help very much (think the error may be coming in more than one place)

It would really help if I could see exactly what was being executed at the time this error was thrown, eg if it's a function that's causing the error.

If anyone has any advice about that it would be really useful.

You could use SQL Profiler if you have access. I, personally, find these errors when I'm joining ID columns or during a UNION. It's a PITA, but you could check your subqueries and see what comes back, then check what columns it's supposed to join on and check the data type. Or you could spend a couple more hours trolling on SO/TechNet/SQLServerCentral/etc... =]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM